AWK Extract Value from Each Column – How to

awktext processing

I have a file with many rows as below. I just want to extract columns 2,3,5,6; but the third column without the 'chr' prefix:

Input:

585     ENST00000417324 chr1    -       34553   36081   36081   36081   3  

Output:

ENST00000417324 1 34553 36081

I would use awk as the task is very simple, but I don't know how to get rid of the 'chr' prefix.

Thank you!

Best Answer

You could substitute chr at the beginning of the third field with an empty string:

awk '{ sub(/^chr/,"",$3); print $2,$3,$5,$6 }' file
Related Question