i would like to cut off the first 9 characters of each 4th line. I could use cut -c 9
, but i don't know how to select only every 4th line, without loosing the remaining lines.
Input:
@V300059044L3C001R0010004402
AAGTAGATATCATGGAGCCG
+
FFFGFGGFGFGFFGFFGFFGGGGGFFFGG
@V300059044L3C001R0010009240
AAAGGGAGGGAGAATAATGG
+
GFFGFEGFGFGEFDFGGEFFGGEDEGEGF
Output:
@V300059044L3C001R0010004402
AAGTAGATATCATGGAGCCG
+
FGFFGFFGFFGGGGGFFFGG
@V300059044L3C001R0010009240
AAAGGGAGGGAGAATAATGG
+
FGEFDFGGEFFGGEDEGEGF
Could you please try following, written and tested with shown samples in GNU awk
.
awk 'FNR%4==0{print substr($0,10);next} 1' Input_file
OR as per @tripleee's suggestion(in comments) try:
awk '!(FNR%4) { $0 = substr($0, 10) }1' Input_file
Explanation: Adding detailed explanation for above.
awk ' ##Starting awk program from here.
FNR%4==0{ ##Checking condition if this line number is fully divided by 4(every 4th line).
print substr($0,10) ##Printing line from 10th character here.
next ##next will skip all further statements from here.
}
1 ##1 will print current Line.
' Input_file ##Mentioning Input_file name here.
Maybe even refactor down to
awk '!(FNR%4) { $0 = substr($0, 10) }1'
Worked perfectly to resolve the first issue, thanks!!!
@gnikixam, I think your cut off 9 characters on every 4th line + performance issue both should be addressed by this one IMHO.
Yeah that's right. But second aim is, to remove additionally XY characters at the end of this line. For example: line 4 the last 3 characters, line 8 the last 5 characters and so on. This is very time consuming
@gnikixam, I really thought both are same requirement only :) Do lines where you want to remove characters at last have any specific sequence or logic in their line number? Kindly do let me know.