grep : grep command is used to search a string and regular expression from a given file.
Syntax:$grep <string/pattern> filename
Ex :$grep india demo
It prints then line containing india.
Ex :$grep india demo demo1 demo2
It search india string from demp,demo1 & demo2 files and print lines having india.
Ex :$grep india *
It searches the india string from the current directory of all files.
Ex :$grep "indian politics" demo
Use of grep command with options:
a)Syntax :$grep -i "String" <filename>
Ex :$grep -i "India" demo
This command ignores case sensitive.
b)Syntax :$grep -c "String" <filename>
Ex :$grep -c "india" demo
This command counts number of lines having string india.
c)Syntax :$grep -n "String" <filename>
Ex :$grep -n "india" demo
This command counts lines with line numbers having string india.
d)Syntax :$grep -v "String" <filename>
Ex :$grep -v "india" demo
This command displays the lines do not having string india.
e)Syntax :$grep -o "String" <filename>
Ex :$grep -o "india" demo
This command prints only pattern containing india.
Syntax:$grep <string/pattern> filename
Ex :$grep india demo
It prints then line containing india.
Ex :$grep india demo demo1 demo2
It search india string from demp,demo1 & demo2 files and print lines having india.
Ex :$grep india *
It searches the india string from the current directory of all files.
Ex :$grep "indian politics" demo
Use of grep command with options:
a)Syntax :$grep -i "String" <filename>
Ex :$grep -i "India" demo
This command ignores case sensitive.
b)Syntax :$grep -c "String" <filename>
Ex :$grep -c "india" demo
This command counts number of lines having string india.
c)Syntax :$grep -n "String" <filename>
Ex :$grep -n "india" demo
This command counts lines with line numbers having string india.
d)Syntax :$grep -v "String" <filename>
Ex :$grep -v "india" demo
This command displays the lines do not having string india.
e)Syntax :$grep -o "String" <filename>
Ex :$grep -o "india" demo
This command prints only pattern containing india.
No comments:
Post a Comment