You can search word in file using grep command.
Syntax:
grep [options] <pattern> <file(s)>
Examples with different options:
1. grep anil file1
2. To search exact word in file
grep -w 'anil' file2
3. To search words in multiple files or in directory
grep -r 'anil' /tmp
4. Case insensitive search
grep -i "Anil' file3
Note: If you want to discard errors during above commands execution, then redirect errors in /dev/null using below command [/dev/null is the device where anything you send simply disappears].
$ grep -w 'anil' /tmp/ 2> /dev/null
Syntax:
grep [options] <pattern> <file(s)>
Examples with different options:
1. grep anil file1
2. To search exact word in file
grep -w 'anil' file2
3. To search words in multiple files or in directory
grep -r 'anil' /tmp
4. Case insensitive search
grep -i "Anil' file3
Note: If you want to discard errors during above commands execution, then redirect errors in /dev/null using below command [/dev/null is the device where anything you send simply disappears].
$ grep -w 'anil' /tmp/ 2> /dev/null
No comments:
Post a Comment