linux find case insensitive
Use grep and regular expressions to analyze text
what is grep ?...
‘grep’ is a line searcher specially its very helpful when u are dealing with large text files or even multiple files. Name ‘grep’ drives from unix/linux text editor ed: (global / regular expression /print) g/re/p.
How to Use Grep ?
1 : A simple example of grep (common use) which will find the word ‘savitoj’ from users_name.txt file.
grep savitoj users_name.txt
output of this command will be based on the lines which contains the word ‘savitoj’ or ‘savitoj.com’ will be included in the result. By default grep will show you case-sensitive words i.e ( savitoj.com, savitoj etc ).
2 : Ignore word case-linux find case insensitive. ‘ -i ‘
For expacting all word case you must provide the ‘-i’ option with your command. it will return case-insensitive results.
grep -i savitoj users_name.txt
Above command will ignore case-sensitive words and in the output it will print the lines that contains word. i.e (savitoj, Savitoj, Savitoj.com etc ) respectively.
3 : Search only words. ‘ w ‘
You can specify ‘w’ option in grep command that will show you only the specified word.
grep -w 'savitoj' /var/log/messages
This options will generate the result according to specified word i.e (savitoj.com, dnssavitoj, ftpsavitoj etc)
4: Search two different words with grep
egrep -w 'david | mike' users_name.txt
5 : Recursively ‘ -r ‘
With ‘-r’ option you can search your word recursively in the each directory.
grep -r '192.168.2.1' /etc
6 : Count lines that contains specified word. ‘ -c ‘
grep -c 'kernal' /var/log/messages
‘-c’ option will match the lines that contains word ‘kernal’, in the output you can see counted numbers.
7 : skip the specified word using ‘ -v ‘ option.
you can use lower case ‘v’ option to force grep show the result except the specified word.
grep -v savitoj users_name.txt
Regular expressions :
Regular expressions can be used to analyze or match more complex text pattern.
8 : Search the line that ends with a specified word. ‘$’
grep 'com$' domain_names.txt
the above command’s output will print the lines that ends with ‘com’ from domain_names.txt file.
9 : Search the line that begin with a specified word. ‘^’
grep '^savitoj' domain_names.txt
the above command’s output will print the lines that begins with ‘savitoj’ from domain_names.txt file.