Commands: $ logname  to check present working user. User2 $ clear


$ grep –e “searching pattern” –e “searching pattern” [file name]



Download 122.5 Kb.
Page16/17
Date25.10.2023
Size122.5 Kb.
#62396
1   ...   9   10   11   12   13   14   15   16   17
Unix Commands
$ grep –e “searching pattern” –e “searching pattern” [file name]
To search for multiple patterns
$ grep “pattern” [file1] [file2] [file3]…..
Searching of pattern from multiple files
$ grep “pattern” *
To search pattern from all files in current working directory


Ex:
$ grep “hello” file1
---------hello--------------
-------------hello---------
$ grep –n “hello” file1
1:---------hello--------------
3:-------------hello---------
$ grep –v “hello” file1
---------------------
---------------------
Except the lines containing “hello” are displayed
$ grep –vn “hello” file1
2:---------------------
4:---------------------
$ grep –c “hello” file1
2
$ grep –i“hello” file1
---------hello--------------
-------------hello---------
--------HELLO-----------
$ grep –e “hello” –e “hai” filex
---------hello--------------
-----------------hai----------
-------------hello------------
---------hai------------------

$ grep –ie “hello” –e “hai” filex


---------hello--------------
-----------------hai----------
-------------hello------------
-----HELLO---------------
---------hai------------------
$ grep “hello” file1 file2 file3
File1:---------hello--------------
File1:-----------------hai----------
File2:-------------hello------------
File3:---------hai------------------
$ grep “hello” *.dat
To search for hello pattern in all .dat files
Use case for grep command
Grep is used to segregate (categorization) of data
Requirement
To get all sales dept records and store into one file
$ grep “sales” emp.dat > sales.dat
To get clerks information working under sales dept
$ grep “sales” emp.dat | grep “clerk” > clerk.dat
1   ...   9   10   11   12   13   14   15   16   17




The database is protected by copyright ©ininet.org 2024
send message

    Main page