0

I want to print column 3 and 4 but without printing the headers empty column lines.

header
tap
norm 
X Y       880 1787
X Y       3253 3439

Printing this via awk '{print($3,$4)}' gives

(BLANK lines from header rows)
880 1787
3253 3439

This works to print column 19 only but how would I get it to print both columns?

awk  '$3{print $3}' 
880
3253

I want col3 col4

880 1787
3253 3439

I tried but get only column 3 printed

awk '$3{print $3}''$4{print $4}' 
880
1787
3253
3439
  • 1
    It is easier to get the help you need if you provide the contents of the file you're working with. What do mean by empty column lines? If you just want to print both columns then the man page for awk or google will help you. You're on the right track. – Nasir Riley Apr 10 '18 at 1:26
  • Please format example input and output with code formatting. See unix.stackexchange.com/editing-help/#code – muru Apr 10 '18 at 4:47
1

You know how long the head is (three lines):

awk 'NR > 3 { print $3, $4 }'

NR is the number of records (lines by default) that has been read so far. With NR > 3 we trigger the print statement for the fourth line and all lines after.

You could use

awk '$3 { print $3, $4 }'

but this is a bit fragile as it depends on not only $3 being present but also that it is non-zero (a zero in the third column would give no output for that line).

0

If

header
tap
norm
X Y 880 1787
X Y 3253 3439

Then

awk '{print $3 " " $4}' | sed '/^ *$/d'

Makes

880 1787
3253 3439

And for your last part you can try

 awk '{print $3 " " $4 " " $19}'

To print the 3rd, 4th and 19th columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.