

You should see the following output: file1.txt:1:tecadmin is a popular linux blogįile2.txt:2:linux is made by linus torvalds.įile2.txt:3:linux is most popular operating system.įile3.txt:2:Ubuntu is a linux operating system You can use grep with -n option to print line numbers with matching patterns.įor example, to display line number that matches the pattern linux in the current directory, run the following command: grep -n linux * You should see the following output: file1.txt:2ĭisplay Line Number with Matching Pattern You can use grep with -c option to display all files with the number of lines that matches the given string.įor example, to display all files with the number of lines that matches a string linux in the current directory, run the following command: grep -c linux * You should see the following output: file1.txt You can display only filenames that contain a specific string using -l option.įor example, list all filenames in the current directory that matches the string tecadmin, run the following command: grep -l tecadmin * To List Filenames That Matches Specific Pattern This command will exclude all the lines that contain the string linux: file1.txt:i love tecadmin You can use grep command with -v option to print all lines that do not match a specific pattern of characters.įor example, print all lines that don’t contain the string linux in file1.txt and file2.txt, run the following command: grep -v linux file1.txt file2.txt This command will print all lines that contain a word linux in all files in the current directory and sub-directories: file1.txt:tecadmin is a popular linux blogįile3.txt:Ubuntu is a linux operating system To search for a string linux in all files in the current directory and sub-directories, run the following command: grep -r linux *.This command will print all lines that contain a word linux in file1.txt and file2.txt: file1.txt:tecadmin is a popular linux blogįile2.txt:Linux is an open-source operating system.įile2.txt:linux is made by linus torvalds.įile2.txt:linux is most popular operating system. To search for a string linux in file file1.txt and file2.txt, run the following command: grep -i linux file1.txt file2.txt.To Search a Specific String in Multiple File This command will print all lines that contain a word tecadmin case insensitively: tecadmin is a popular linux blog To search for a string tecadmin case insensitively in the file file1.txt, run the following command: grep -i tecadmin file1.txt.This command will print all lines that contain a whole word tecadmin: tecadmin is a popular linux blog To search for an exact string tecadmin in the file file1.txt, run the following command: grep -w tecadmin file1.txt.This command will print all lines that contain a word tecadmin: tecadmin is a popular linux blog To search for a string tecadmin in the file file1.txt, run the following command: grep tecadmin file1.txt.A system running the Linux operating system.
WINDOWS COMMAND SEARCH FILES FOR TEXT STRING HOW TO
In this tutorial, we will show you how to use the Grep command with some practical examples. Suggested Read: 12 Awesome Linux Find Command Examples.So Grep command can be used to search some kind of text, word, pattern or sentence in a text file or a number of text files. Basically, Grep searches a text file for the specified regular expression and outputs any line containing a match to standard output. Grep is a powerful tool for searching a text, Grep means “Global regular expression print”.
