Surprisingly hard to find a good example of this one. Say I have this command:

ps -aeF

the 7th column is the processor # (?). I just want to filter by processses running on the 2nd core. How can I do that? The problem of course if if I do:

ps -aeF | awk '{print $7}' | grep 2

then I only get single column not printing all the columns..

  • 2
    You mean like ... | awk '$7==2' ? – steeldriver Mar 30 at 0:45
  • yeah like that please add an answer, that is nicer than the if block that I had in my awk command so it's an improvement on what I found with my search – Alexander Mills Mar 30 at 1:06

Awk scripts consist of pairs of patterns and actions that are executed when the pattern evaluates logically true. So you can use

... | awk '$7==2 {print}'

or more succinctly, because {print} is the default action

... | awk '$7==2'
| improve this answer | |

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.