Grep Command with Regular Expression
Grep is used to search in content as per our requirement using different options, using this command we can save our time why late lets know about Grep command.
Grep stands for Global Regular Expression Parser,
Syntax for Grep command
grep < > filename
cat filename | grep <string>
i have raja.txt with below content
ABC
abc
bcd
cde
123
234
....etc
output
cde
ouput
ABC
abc
bcd
123
234
output
ABC
abc
output
abc
bcd
123
output
abc
bcd
123
output
ABC
abc
bcd
cat raja.txt | grep | “done$”
Grep stands for Global Regular Expression Parser,
How to check grep command available on our machine ?
grep -VHow to install grep if not available in out machine ?
sudo yum install grepSyntax for Grep command
grep < > filename
cat filename | grep <string>
i have raja.txt with below content
ABC
abc
bcd
cde
123
234
....etc
1.How to search matched string in using grep command
cat raja.txt | grep cdeoutput
cde
2.How to search string without matched files
cat raja.txt | grep -v cdeouput
ABC
abc
bcd
123
234
3.How to search string with case sensitive
cat raja.txt | grep -i abcoutput
ABC
abc
4.How to print string with below n lines
cat raja.txt | grep abc -A 2output
abc
bcd
123
4.How to print string with above n lines
cat raja.txt | grep 123-B 2output
abc
bcd
123
5.How to print below n line above n line with string
cat raja.txt | grep abc -C 1output
ABC
abc
bcd
Comments
Post a Comment