Search code examples
bashawksedcutfastq

replace any line that starts with the symbol @ using sed, awk, cut


this is simple but I was hoping for a quick command (using sed, cut, awk or something in BASH preferably) to do this:

replace any line that starts with the symbol @:

@<text, on one line, including numbers, letters and colons>

with

@<text, on one line, including numbers, letters and colons>/1

The @ is always consistent, the <text, on one line, including numbers, letters and colons> changes. (It's Fastq format for the bioinformaticians out there).

Example:

@HWI-D00193:58:H73UEADXX:1:1101:1516:2209 1:N:0:ATCACG

change to

@HWI-D00193:58:H73UEADXX:1:1101:1516:2209 1:N:0:ATCACG/1

I know this is simple sorry.


Solution

  • With sed, you can do as below:

    sed "/^@/ s/$/\/1/g" file
    

    This matches lines that start with @ and then appends (substitution at the end to be precise) the /1 on all the matching lines.