Physical Server vs Virtual Server- 5 Key Differences Explained
In the digital infrastructure, server plays a vital role. It serves as the backbone for…
The name, “grep” is indicative of the operation which this command performs. It is executed using the Unix/Linux text editor ed: g/re/p
grep'word' filename grep'string1 string2' filename cat otherfile | grep'something' command | grep'something' command option1 | grep'data' grep --color 'data' fileName
Search /etc/passwd for boo user:$ grep boo /etc/passwd
Users can force grep to ignore word case. Such as, match boo, Boo, BOO and another combination with -i option:$ grep -i "boo" /etc/passwd
User can search recursively. Such as, read all files under each directory for a string “192.168.2.6”$ grep -r "192.168.2.6" /etc/
When the user searches for boo, grep will match fooboo, boo123, etc. Grep can be made to select only the lines which contain matching whole words such as only the word boo.
$ grep -w "boo" /path/to/file
use egrep as follows:$ egrep -w 'word1|word2' /path/to/file
Users can get the number of times which the pattern has been matched for every file with -c (count) option:$ grep -c 'word' /path/to/file
Also keep in mind that the user can utilize -n option, which causes grep to precede every line of output with the number of the line in the text file from which it was obtained:$ grep -n 'word' /path/to/file
The -v option is used to print inverts of the match; meaning that it will return only those lines that do not contain the given word. For example, print all lines that do not contain the word bar$ grep -v bar /path/to/file
grep command is also used with pipes. As follows :# dmesg | egrep '(s|h)d[a-z]'
Display cpu model name:
# cat /proc/cpuinfo | grep -i ‘Model’
Users can use the above command without a shell pipe, like below :# grep -i 'Model' /proc/cpuinfo
Use the -l option to list file names whose contents mention main():$ grep -l 'main' *.c
Users can also force grep to display output in colors:$ grep --color vivek /etc/passwd
Explore more hosting insights, tips and industry updates.
In the digital infrastructure, server plays a vital role. It serves as the backbone for…
Aren’t you struggling to rank in search results because of AI Overviews? Does it feel…
The choice of operating system is the second choice you have to do after choosing…