Introduction to grep
global regular expression print
Grep is at text processing tool. It is a pattern matching tool, which means if we provide a pattern and a file name to grep, "grep" will print all the lines from those files which contains the given pattern.
Contents of the /course/grep/grepsample.txt
global regular expression print
Grep is at text processing tool. It is a pattern matching tool, which means if we provide a pattern and a file name to grep, "grep" will print all the lines from those files which contains the given pattern.
Contents of the /course/grep/grepsample.txt
Grep will try to find out all lines which contains the pattern "file" , and it will print the result on the screen.
This time grep will colour the area of the line which contains the given pattern.
grep can find the pattern by ignoring the case. "-i" option is used for enabling the case ignoring feature.
grep will search for the pattern "this" with case ignoring option ( with upper, lower, or mixed cases ) .
grep will search for the pattern "this" with case ignoring option ( with upper, lower, or mixed cases ) .
This time grep will print all the lines which begins with the pattern "this". We use a "caret" symbol in front of the pattern to instruct grep to only print lines which starts with the given pattern.
This time grep will print all lines which begins with the pattern "linux", because we had put a "caret" symbol(^), before the pattern "linux".
This time grep will print all the lines which ends with the pattern "file". To do this we had put a "$" symbol at the end of the pattern.
Printing line numbers of matching lines, if we use -n with grep then grep will print the matched lines with line numbers
Invert selection using grep: Invert selection will print all the lines that donot contain the given pattern. we use "-v" to enable this feature.
Printing empty lines using grep: To print empty lines just search for this "^$" pattern.
Removing empty lines using grep: To remove all blank lines just invert select blank lines and