bluethundr
February 6th, 2010, 06:41 PM
Hi there,
I am reviewing some of the basics and trying to get a "feel" for how output is chained from command to command.
I am trying to build a solution with awk
To begin let's say that I want to grep the output of top to see if firefox is running...
$ top | grep firefox
Simple.
What if I want to switch gears for a bit and search the output of top and refine what I'm seeing with a bit of formatting:
$ top | awk '{ print "User: " $3 " PID: " $2 " Command: " $13}'
And as a final step let's say I wanted to grep for a specific command:
$ top | awk '{ print "User: " $3 " PID: " $2 " Command: " $13}' | grep firefox
That last command doesn't work. I would like to turn this process into few handy environment variables and replace myself with a small shell script. ;)
I selected "other OS" here, because this question is about as generic as it comes and applies to all unix like systems I can think of.
I am reviewing some of the basics and trying to get a "feel" for how output is chained from command to command.
I am trying to build a solution with awk
To begin let's say that I want to grep the output of top to see if firefox is running...
$ top | grep firefox
Simple.
What if I want to switch gears for a bit and search the output of top and refine what I'm seeing with a bit of formatting:
$ top | awk '{ print "User: " $3 " PID: " $2 " Command: " $13}'
And as a final step let's say I wanted to grep for a specific command:
$ top | awk '{ print "User: " $3 " PID: " $2 " Command: " $13}' | grep firefox
That last command doesn't work. I would like to turn this process into few handy environment variables and replace myself with a small shell script. ;)
I selected "other OS" here, because this question is about as generic as it comes and applies to all unix like systems I can think of.