This can be used in grep to match the lines which end with the given string or pattern.ġ0.Specifies expression with -e option. Matching the lines that end with a string : The $ regular expression pattern specifies the end of a line. This can be used in grep to match the lines which start with the given string or pattern.ĩ. Matching the lines that start with a string : The ^ regular expression pattern specifies the start of a line. Inverting the pattern match : You can display the lines that are not matched with the specified search string pattern using the -v option.Ĩ.
unix is free os.Ĥ:uNix is easy to learn.unix is a multiuser os.Learn unix. Show line number while displaying the output using grep -n : To show the line number of file with the line matched.ġ:unix is great os. We can make the grep to display only the matched string by using the -o option.Ħ. Displaying only the matched pattern : By default, grep displays the entire line which has the matched string. The -w option to grep makes it match only the whole words.ĥ. Checking for the whole words in a file : By default, grep matches the given string/pattern even if it is found as a substring in a file. $grep -l "unix" * or $grep -l "unix" f1.txt f2.txt f3.xt f4.txtĤ. Display the file names that matches the pattern : We can just display the files that contains the given string/pattern. Displaying the count of number of matches : We can find the number of lines that matches the given string/patternģ. It matches the words like “UNIX”, “Unix”, “unix”.Ģ. Case insensitive search : The -i option enables to search for a string case insensitively in the given file. UNix is easy to learn.unix is a multiuser os.Learn unix. C n : Prints searched line and n lines after before the result. B n : Prints searched line and n line before the result. A n : Prints searched line and nlines after the result. With each such part on a separate output line.
o : Print only the matched parts of a matching line, E : Treats pattern as an extended regular expression (ERE) f file : Takes patterns from file, one per line. e exp : Specifies expression with this option. v : This prints out all the lines that do not matches the pattern n : Display the matched lines and their line numbers. h : Display the matched lines, but do not display the filenames. Options Description -c : This prints only a count of the lines that match a pattern