Search string or words in logs without using Grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search string or words in logs without using Grep
# 8  
Old 07-30-2015
Code:
perl -ne '/1215456/ and print' *.log

# 9  
Old 07-30-2015
There are lots of utilities that can emulate grep. Few, if any, of them will be faster or use less memory than grep for the options you're using. Since you're using fixed strings rather than regular expressions, you could make grep run faster by using the -F option. But, you didn't mention searching compressed and/or gzipped files until post #7 in this thread. Uncompressing or unzipping a file and searching the converted plain text is obviously going to take a LOT more memory and/or swap space and a LOT more time than searching a plain text file.

The fact that you're processing your compressed files, your gzipped files, and your plain text files with:
Code:
zgrep 11263511 *.trace.log*

and processing your plain text files with names containing .trace again with:
Code:
grep 1215456 *.trace.log

probably won't affect swap space, but it will make processing the files in your directory take longer.

If you have the space, you'd be better off keeping your log files uncompressed until you're done searching them. With uncompressed, unzipped files, grep shouldn't need a lot of memory or swap space. I have no idea whether zgrep takes a lot more memory and swap, but I wouldn't be surprised if it does.

If you want to search for two (or more) patterns in all of your log files, it will take a minuscule bit more space and run a LOT faster if you combine them in a single invocation of grep.

For example:
Code:
zgrep -Fe 11263511 -e 1215456 *.trace.log.*
grep -Fe 11263511 -e 1215456 *.log

If the zgrep commands really are taking too much swap, you might need less if you uncompress your compressed files, gunzip your gzipped files, grep the files you uncompressed and unzipped, and then compress or gzip them again. (But, that will be slower, and uncompress and gunzip may eat up as much swap as zgrep.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep multiple words in a file with help of fixed string switch

I have multiple strings in a file which have special character $, when i search strings by ignoring $ with \ using single quotes it returns empty results. My search strings are set char_1($lock) and set new_char_clear_3($unlock) I tried searching with but it returns empty results.However... (3 Replies)
Discussion started by: g_eashwar
3 Replies

2. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

3. Shell Programming and Scripting

Grep only words containing specific string

Hello, I have two files. All urls are space seperated. source http://xx.yy.zz http://df.ss.sd.xz http://09.09.090.01 http://11.22.33 http://canada.xx.yy http://01.02.03.04 http://33.44.55 http://98.87.76.65 http://russia.xx.zz http://aa.tt.xx.zz http://1w.2e.3r.4t http://china.rr.tt ... (4 Replies)
Discussion started by: baris35
4 Replies

4. Shell Programming and Scripting

Number of words in line, while loop, search and grep

Hello, What I wish to attain is: - to read fileA line by line - search entire line as string in fileB - when found, grep the next line in fileB - then merge "searched line" and "found line" in a new file, fileC Here is my fileA: T S Eliot J L Borges L Aragon L L Aragon T S Eliot 4 0... (17 Replies)
Discussion started by: baris35
17 Replies

5. Shell Programming and Scripting

Grepping the logs with respect to string search

Hi Folks, I have a log file at the following location.. /opt/ert/abc.log Now abc.log contain the following enteries in this format below.. 23-Jul-2014 10:09.32.204 ERROR abc.log cdfrer tyre fgty >>>>> cqno : 78539132 abc Id : 0 Sabc : 20140724 Now in log file (abc.log) I want to... (2 Replies)
Discussion started by: tuntun343466
2 Replies

6. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

7. Shell Programming and Scripting

script to grep latest outofmemory string from the logs

I have requirement to prepare script which will grep for latest outofmemory message from the logs. I have used following command to grep the string from the logs,this script is not effective when logs are not getting updated as it will grep for old message. f=catalina.out var=`tail -10 $f |... (17 Replies)
Discussion started by: coolguyamy
17 Replies

8. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

9. UNIX for Dummies Questions & Answers

search multiple words using grep

Hi frnds i want to desplay file names that should be word1 and word2 ex : i have 10 *.log files 5 files having word1 and word2 5 files having only word1, i have used below command egrep -l 'word1|word2' *.log its giving all 10 files, but i want to display only 5... (20 Replies)
Discussion started by: pb18798
20 Replies

10. UNIX for Dummies Questions & Answers

grep with find to search for matchiing words

Hi all, Please help me in the following dbt i want to know the different files in the current and the sub directory which have some search key in that . for example i want to know all filenames followed by the word 'unix' in all files. the file name and the matching word have... (1 Reply)
Discussion started by: akhil313
1 Replies
Login or Register to Ask a Question