I am using the following code to modify all odd lines in a file:
awk 'NR % 2 { print } !(NR % 2)' FWD-1.fas | cut -c5-600
I however, do not want cut to affect the odd lines
Any help?
I am using the following code to modify all odd lines in a file:
awk 'NR % 2 { print } !(NR % 2)' FWD-1.fas | cut -c5-600
I however, do not want cut to affect the odd lines
Any help?
Don't use cut. awk equivalent is substr($0,5,595)
try:
awk '!(NR%2) { print substr($0,5,595); next; } 1' FWD-1.fas
Hi Xterra,
The pipeline you have is logically equivalent to:
cut -c5-600 FWD-1.fas
but runs slower since you're reading and writing the file twice instead of just once.
Hi Neutronscott,
I think you have an off-by-1 error in the substring. What you have would emulate cut -c5-599
I would try something like:
awk '!(FNR % 2) {$0 = substr($0, 5, 596)} 1' FWD-1.fas
oy. darn 1-index. Thanks, Don.
but yes, everything outputted by awk goes to cut. cut doesn't have logic like awk does. But awk can determine if it's an odd line and also skip the first 5 characters.
the 1 at the end is shorthand for {print $0} , so that lines that weren't modified will still be printed as they were.