Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Using grep to filter a text file (Read 12676 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Using grep to filter a text file
18.06.06 at 15:01:14
 
Using grep to filter a text file
 
On UNIX and LINUX systems the grep utility can be used to filter a text file. Together with pipes you can direct the output to other grep commands to apply other filters on the results.
 
Example:
Suppose I want to view all lines from my webserver's weblog called access_log that contain the word sqlxl:  
grep sqlxl access_log
 
If I want to filter the resulting lines not displaying any activity from googlebot I would write:
grep sqlxl access_log | grep -v googlebot
 
If I also want to filter out the inktomi search bot I would continue like this:
grep sqlxl access_log | grep -v googlebot | grep -v inktomisearch
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Re: Using grep to filter a text file
Reply #1 - 18.06.09 at 13:55:20
 
To reverse the result, to display files without the searched string, use the -L option:
 
Display all files without the text Happy landing.
grep -L "Happy landing" output*
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
grep with multiple conditions
Reply #2 - 24.04.11 at 12:19:13
 
grep with multiple conditions
 
With the -e option multiple conditions can be set to filter the text file.  
 
For example, to filter all lines containing Hello and all lines containing Goodbye from a text file called hi.txt, the following command can be used:
grep -e Hello -e Goodbye hi.txt
 
A more elaborate example:
Scan new lines adding to .output files (tail -f *.output)
Filter those lines and display when they contain " at ", spent or ==>
tail -f *.output | grep -e " at " -e "spent" -e "==>"
 
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1