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
# 1  
Old 07-29-2015
Search string or words in logs without using Grep

I'm in need of some kind of script that will search for a string in each logfile in a directory but we don't want to use GREP. GREP seems to use up to much of our memory causing the server to use up a lot of swap space. Our log files are bigger than 500M on a daily basis. We lately started turning over our logs when it reaches 1G to help but it seems to still use up a lot of our memory causing the server to use up too much of its swap space.

Any recommendation on how we can search for strings/words in each logfile thats within a directory without having to use grep?
# 2  
Old 07-29-2015
You might try something like this (untested):
Code:
SEARCH="this string"
awk -v S="$SEARCH" '/S/ {print $0}' *

However, i'm pretty the issue is NOT grep.
In fact, it is probably due to wrong usage (eg: too many pipes).
The more commands you use for a single search/compare the longer it takes and the more memory it uses.

hth
# 3  
Old 07-29-2015
You can probably do it with sed or awk. What characters are in your search pattern? Are you looking for a fixed string, a match for a basic regular expression, or a match for an extended regular expression? Are you hoping to get a count of matching lines, a list of the matching lines, the line numbers of lines that match?

What options are you giving to grep when you use it to search for a string in each log file in a directory?

What operating system and shell are you using?
# 4  
Old 07-29-2015
Quote:
Originally Posted by sea
You might try something like this (untested):
Code:
SEARCH="this string"
awk -v S="$SEARCH" '/S/ {print $0}' *

However, i'm pretty the issue is NOT grep.
In fact, it is probably due to wrong usage (eg: too many pipes).
The more commands you use for a single search/compare the longer it takes and the more memory it uses.

hth
That won't work! The /S/ will print lines containing the character S. If the search string doesn't contain any characters that are special in an ERE, the following should work:
Code:
awk -v S="$SEARCH" '$0 ~ S' *.log

if the goal is just to print the matching lines and the target OS is not a Solaris/SunOS system.
# 5  
Old 07-29-2015
the characters vary. sometimes we need to find a particular transaction id, look for errors, or a particular word.

Code:
> uname -a
Linux xx.xx.xx.com 2.6.18-371.6.1.el5 #1 SMP Tue Feb 18 11:42:11 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

> ps -p $$
  PID TTY          TIME CMD
 5140 pts/0    00:00:00 ksh

# 6  
Old 07-29-2015
I repeat: What grep command-line are you using to get the output you want?
# 7  
Old 07-29-2015
here are some examples
Code:
zgrep 11263511 *.trace.log*
grep 1215456 *.log


We are not sure which grep command is what crashes the server. Our performance team can only see that its a grep command that causes the spike in swaps space.
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