The zgrep, a derivative of grep command, can be used for searching in gzipped files. $ grep -v '^test' /etc/passwd Search a string in Gzipped Files using zgrep For example: $ grep -v test /path/to/file If you want to excludet the given word then use the –v option in grep command. It displays the line number from the file of the specified search string: $ grep –n "main" setup.py The –v option example for invert match The –n option for grep is quite helpful when debugging files through compile errors. $ grep -i 'text' /path/to/file Search Files by Given String
For example, searching for “text” matches Text, texT, TEXT etc. We can force grep to ignore case distinctions in data and patterns.
#Grep linux how to#
match just “text” word: $ grep -w "boo" file How to use grep to search two Distinct wordsĪn example of searching two words: $ egrep -w 'string1|string2' /path/to/file Count Number of Matches example # ifconfig | grep -c inet6 How to perform case insensitive search The grep command is handy when searching through large log files. When it finds a match, it prints the line with the result. The text search pattern is called a regular expression. You can force the grep command to choose only those lines containing matches that form whole words i.e. Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. When you search for “text”, grep will fit textdemo, text123, textmore etc. name "*.mp3" | grep -i Haynes | grep -vi "tutorial" Using –w option to search for specified word only With a find command with a couple of grep pipes will do the trick: $ find. You are searching for all the *.mp3 files from the person Haynes, but you do not need any of the tutorial audio files.
By way of instance, let’s say you have an entire folder full of audio files in a whole lot of different formats. The grep can be extremely helpful for filtering from stdout. The example command below will search in all files for a given string: $ grep -r "some_text" /etc/ How to find all files with a specific extension Use the –r option in grep command for searching recursively. You may also use fgrep command as well: $ fgrep Mango fruits.txt How to use grep recursively An example of searching a file grep testUsr /etc/passwd Searching a word in a specified file exampleįor finding a word in the specified file, you may use a grep command as follows: $ grep Mango fruits.txt