0

let say, I have table in the imagewhich is basically "qstat" of HPC jobs:

I like to print out columns 2 and 6 which match NDS==1 and TSK==1 I am using command:

qstat -a |grep ' $4=="1" $5=="1" ' |awk '{print $2, $6}'

It shows no output with no error message. What I am missing?

1

You are confusing grep and awk slightly.

With grep ' $4=="1" $5=="1" ', grep would interpret $4=="1" $5=="1" as a regular expression. This expression would try to match a 4 occuring after the end of the line ($), which can never happen.

Instead:

qstat -a | awk '$4 == "1" && $5 == "1" { print $2, $6 }'

If you want the header as well:

qstat -a | awk 'NR == 1 || ($4 == "1" && $5 == "1") { print $2, $6 }'
  • Thanks. Why NR == 1 ? – Akand Apr 3 '18 at 15:32
  • @Akand That would trigger the print statement for the header line as well (the first input line which has NR equal to 1), so that you get the column names. This is what I meant by "if you want the header as well". – Kusalananda Apr 3 '18 at 15:34
  • @Akand If this solves your issue, please consider accepting the answer. – Kusalananda Apr 3 '18 at 15:57

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.