[SYNTAX] grep command
[SYNTAX] grep command
The grep command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
Simple Example
Case-insensitive Search (-i)
-i option is used to ignore case in search.
Multiple Pattern (-e)
-e option is used to search for multiple patterns in a file.
Complete Word Search (-w)
Select only those lines containing matches that form whole words.
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
Simple Example
- Code:
$ cat 1.txt
hi u der
make hi files wonderful
things computer windows
hi make ubuntu files
recover delete hi things
computer
computerjee
Hi Computer working!!!
$ grep 'computer' 1.txt
things computer windows
computer
computerjee
Case-insensitive Search (-i)
-i option is used to ignore case in search.
- Code:
$ grep -i 'computer' 1.txt
things computer windows
computer
computerjee
Hi Computer working!!!
Multiple Pattern (-e)
-e option is used to search for multiple patterns in a file.
- Code:
$ grep -e 'hi' -e 'computer' 1.txt
hi u der
make hi files wonderful
things computer windows
hi make ubuntu files
recover delete hi things
computer
computerjee
Complete Word Search (-w)
Select only those lines containing matches that form whole words.
- Code:
$ grep -w 'hi' 1.txt
hi u der
make hi files wonderful
hi make ubuntu files
recover delete hi things
Permissions in this forum:
You cannot reply to topics in this forum
|
|