This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Substitute first column based on second column

Hi,

I have files with lines that look like

HSQ1008:141:D0CC8ACXX:3:1106:17255:124378       163     chr14

I'm wondering how I can output a file that appends /1 if the second column is 99 or 83 and a /2 if the second column is 163 or 147. Also I want to put \n + \n between each the second and third column, a \n after the first and last column, and an "@" in front of the very first column. So I would want the above line to become

@HSQ1008:141:D0CC8ACXX:3:1106:17255:124378/2
163
+
chr14

I appreciate any help!

awk

1 answer

awk '{if ($2 == 99 || $2 == 83) print "@",$1,"/1\n",$2,"\n+\n",$3"\n"; else if ($2 == 163 || $2 == 147) print "@",$1,"/2\n",$2,"\n+\n",$3,"\n"; else {}}'  sam_file.sam

I haven't tested it but you should tweak around and make it to work if it throws any error.

Thanks! Just needed to take the commas out but this worked great!

Log in to answer this question.