#DecodeITeS
The grep command is used to search text in Linux Environment.
It searches the given file name for lines containing a match to the given strings or words under the command. It is one of the most useful commands on the Linux and Unix-like systems.
The name, “grep”, derives from the command used to perform a similar operation under environment, using the Unix/Linux text editor ed:
g/re/p
The grep utilities are a family that includes grep, egrep, and fgrep for searching duties for files. For most uses, you need to use fgrep command as it the fastest and only look into strings and words. However, typing grep is easy.
Syntax of grep commands:
grep 'word' filename
fgrep 'word-to-search' file.txt
grep 'word' file1 file2 file3
grep 'string1 string2' filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName
grep [-options] pattern filename
fgrep [-options] words file
Standard grep command examples:
Below is some standard grep command to get you started with grep on Linux, macOS, and Unix:
Search any line that contains the word in filename on Linux: grep 'word' filename
Perform a case-insensitive search for the word ‘***’ in Linux and Unix: grep -i ‘***' file1
Look for all files in the current directory and in all of its subdirectories in Linux for the word ‘***’: grep -R ‘***'
Search and display the total number of times that the string ‘****’ appears in a file named ‘***’: grep -c ‘****’ ***
Watch video Learn grep command in 10 minutes online without registration, duration hours minute second in high quality. This video was added by user Decode ITES 10 June 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 562 once and liked it 6 people.