How to Grep Output of a Program in a Linux Terminal

(0 votes, average 0 out of 5)

Grepping the output of a script or program in a linux terminal is very straightforward.  Run the script or program and pipe the output to grep, leaving the file designation empty.

myprog -h | grep "Usage"

The vertical bar indicates a piped output to a different program -- in this case, grep.  The example above will return all lines which contain the substring "Usage".

Partner Links:
Last Updated on Tuesday, 14 February 2012 12:20  
Related Articles

» Redirect all output in shell script to a file

Redirecting a single command in a script to a file is straight-forward using the > syntax. For example, to redirect all STDERR output:1echo "hello, world" 2>> /tmp/filename.logTo redirect all lines of a Bash script to a file, add a scope around all of the lines and then redirect the scope to a file. For example:123456(echo "this is line 1 of my script"cat /proc/cpuinfodmesgecho "this is the end of my script") 2>> /tmp/filename.logThis allows you to capture all output of a script...

» How to Find a Process Using a Particular Port in Linux

If you are trying to find the process using a particular port in Linux, you can do the following: lsof -i tcp:2700 The above example will return a list of processes using the TCP port with ID 2700.Alternatively you can view all open network connections by doing the following: sudo netstat -nlp 

» Find and Replace Text in Multiple Files

Sometimes it is useful to be able to replace a certain piece of text in multiple files, even across multiple folders. Opening each file and using find/replace is tedious. Fortunately, there is a much easier way using the sed and grep utilities. For Windows users, please to get these programs on your system. Linux and Mac OS X users will already have these programs pre-installed.Launch a terminal window, and cd to the root directory where all of these files and folders exist. Once in the...