Substitute first column based on second column
1
0
Entering edit mode
9.0 years ago
jyu429 ▴ 120

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.7k views
ADD COMMENT
4
Entering edit mode
9.0 years ago
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.

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1861 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6