grep

The grep command can be found on all flavors of linux and unix and is basically checks for lines that match your input. So for example, if I had the following text file names.out:

Bobby Joe

Ted Dan

Susan Jan

I can get the line that matches Dan with:

#  grep Dan names.out

Ted Dan

Or to ignore case:

# grep -i dan names.out

Ted Dan

I can also get everyline that doesn't match my pattern:

# grep -v Dan names.out

Bobby Joe

Susan Jan

Also regular expressions can also be used too. Let's try for, lines that begin with K-Z:

 # grep -e "^[K-Z]" names.out

Ted Dan

 Susan Jan

The real benefit of grep is to use it conjunction with other commands using the pipe symbol '|'. Let's use with snoop to get any information concerning NIS:

# snoop |grep -i nis

Or how about we grep for a command that's running:

# ps -ef |grep gnome

This entry was posted in software and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *