#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 ‘****’ ***
Смотрите видео Learn grep command in 10 minutes онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Decode ITES 10 Июнь 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 562 раз и оно понравилось 6 людям.