0

I've got it working as expected when looking at 1 column:

cat /tmp/inputfile | awk -F : '$12 !~ /100/ { print $6,$12,$13}'
cat /tmp/inputfile | awk -F : '$12 ~ /100/ { print $6,$12,$13}'
4726753 100 137

But when I try to make the next step in the process (look at 2 columns and print if the pair is not "100 137" it prints under BOTH conditions. Since it simultaneously meets both conditions (does match and does not match), it must be ignoring my conditional right?

cat /tmp/inputfile | awk -F : '$12,$13 ~ /100 137/ { print $6,$12,$13}'
4726753 100 137
cat /tmp/inputfile | awk -F : '$12,$13 !~ /100 137/ { print $6,$12,$13}'
4726753 100 137

Fixing/understanding this is step 1. The finished result should check for "100 137" and "0 0" and only print if $12,$13 are neither of those pairs.

  • 1
    1) not sure what is -F : is used for. 2) awk '$12 != 100 && $13 != 137' ? – Archemar May 10 '18 at 17:44
  • The field separator is : rather than <space> – doneladio May 10 '18 at 17:47
  • Useless Use of Cat. Don't cat file | awk 'stuff'; just awk 'stuff' file. – DopeGhoti May 10 '18 at 18:04
0

If I read your question correctly, you are looking to print fields 6, 12, and 13 if and only if fields 12 and 13 are not either (100, 137) or (0, 0). So:

awk -F: '! ( ( $12 == 0 && $13 == 0 ) || ( $12 == 100 && $13 == 137 ) ) { print $6, $12, $13 }' inputfile
  • There's a small typo in the first conditional (should be $13 == 0) but this works. Thanks so much. – doneladio May 10 '18 at 18:13
  • Good catch; fixed. – DopeGhoti May 10 '18 at 18:30

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.