G
gcawood
Guest
grep is such a powerful little tool that the number of ways to use it are really limitless. However, if you are just starting out, try to put these into your head..
Code:
# find all occurrences of word in a specified file
grep word file
#exclude word from result
grep –v word
#return the line and the next 2 lines after it.
grep –A 2 word file
#match only one occurrence of word
grep word | head -1
#repeat any character any number of times
grep .*
#whole word match
grep -w 'word' *
#To find 1.gif in a file use, use \ to get around reg-x
grep '1\.gif' file
#Searches for word in all file recursively in the directory /DIR and the /dev/null shows the file name
grep -r word /DIR /dev/null