Searching mutiple word - Tuning grep command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching mutiple word - Tuning grep command
# 1  
Old 08-08-2008
Lightbulb Searching mutiple word - Tuning grep command

Hi all,

I have a log file which is more than 1GB, i need to take count from the log file for two strings. i am using the below command but it take a long time to excetue, i need to tune this. Please help me


cat /logs/gcbs/gcbsTrace.log | grep -i "ViewStatementBusinessLogic" | grep -c -i "MYCACommunicationException"

similary i need to check the count for other execption too. Is there any simple way is avialable.

Regards,
Senthilkumar AK
# 2  
Old 08-08-2008
It's probably better if you post realistic examples and keep all the discussion in a single thread. See https://www.unix.com/shell-programmin...s-my-code.html and https://www.unix.com/unix-advanced-ex...ck-script.html

As such, I would recommend that you combine all your grep statements to a single sed script.

Code:
sed -n '/regex1/s/.*\(regex2\).*/\1/p
/regex3/s/.*\(regex4\).*/p
/regex5/s/.*\(regex6\).*/p' /logs/gcbs/gcbsTrace.log | sort | uniq -c

That way, you only scan the whole file once, and spend less time waiting for the disk.
# 3  
Old 08-08-2008
Thanks era,

The Sed command also takes the same time as the grep takes, also i take the suggestion which you posted and continue in this thread alone.
# 4  
Old 08-08-2008
If you really need to improve performance, you need to move away from a shell script
and write something in C or C++
# 5  
Old 08-08-2008
ok is it i can write a c program and use this in Linux machine..? I searched in the machine and found perl is there.
# 6  
Old 08-11-2008
The point with the sed is that it takes more time than a single grep, but you can replace all the greps with a single sed script.

Unless you are a skilled C programmer, I doubt that you can make this a lot faster by switching languages. C programs are compiled, you don't need the C compiler on the box itself in order to run the resulting binary.
# 7  
Old 08-11-2008
You can give awk a try:

Code:
awk '{$0=tolower($0)}
/viewstatementbusinesslogic/ && /mycacommunicationexception/{c++}END{print c++}
' file

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge mutiple lines into one based on if the first word is some particular value

Hi, trying to knock something together to create one line entries based on whether the first word on each line matches a particular value. eg. Link,"Name=""Something\something"","Timeout=""1800""", "Target=""\\thing\thing\thing""","State=""ONLINE""",something,... (0 Replies)
Discussion started by: adamdb
0 Replies

2. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

3. UNIX for Dummies Questions & Answers

Grep - Searching for multiple items using one command

I am performing a regular check on UNIX servers which involves logging onto UNIX servers and using the grep command to check if a GID exists in the /etc/group directory e.g. grep 12345 /etc/group I have five to check on each server, is there anyway I can incorporate them into one command and... (2 Replies)
Discussion started by: @MeDaveT
2 Replies

4. Shell Programming and Scripting

Command to grep a word and print the whole line splitted into many

Hi, I need to search a word in the java file. Assume the line in the java file is, (the line was splitted into 3 lines) 1.operationContext.sendFeedback(2.FeedbackType.ERROR, null, "Input is empty.", "Input Details: pr 3.ovide Valid pair(s): "+pairType); When i grep for the word... (6 Replies)
Discussion started by: tulasiram
6 Replies

5. Shell Programming and Scripting

Grep mutiple patterns with 'AND' operator

Hello, I'm trying for days to do a grep without any success. :wall: I have two patterns being: 1 - Master en Achats 2 - complet $ find /var/www/mysite/uploads/files/*.doc -exec egrep -l --ignore-case "Master en Achats|complet" {} \; The problem is that the grep command is done with an... (15 Replies)
Discussion started by: sjolicoeur
15 Replies

6. UNIX for Dummies Questions & Answers

Can grep command return word instead of complete line

Hi Is there any way GREP command can return word and not complete line. My file has following data: Hello Everyone I am NitinrajSrivastava Hi Friends Welcome VrajSrivastava I am using grep 'raj' which is returning me complete line.However I want only the word having keyword 'raj'. Required... (11 Replies)
Discussion started by: dashing201
11 Replies

7. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

8. Shell Programming and Scripting

searching in a while where a word is not there.

Hi, I am new to unix, pls help I have a file suc_Logfile file. liek this. output success success abc Now i need to generate a file in shell script where it shows only abc. Now i am doing like this grep "^successfully\|$" $suc_Logfile >> $Final_Suc Pls help. Thanks,... (6 Replies)
Discussion started by: sailaja_80
6 Replies

9. Shell Programming and Scripting

searching using grep command

Hi, i have a file called alert_pindb.log i need to grep and count for all the lines starting with "ORA-" but i need to exclude the line which is having "ORA-00600 " i am using following syntax to count the ORA- nos "grep \"ORA-\" alert_pindb.log | wc -l"; since ORA- may be anything... (9 Replies)
Discussion started by: prakash.gr
9 Replies

10. UNIX for Dummies Questions & Answers

Find Exactly word in grep command

Hi all How can i find Exactly line using grep. my input file: avg_configfile: Recalculation Dates|4| Recalculation|147| I tryed like; grep ^"Recalculation" avg_configfile out put; Recalculation Dates|4| Recalculation|147| But i want second line avg_configfile.i.e... (4 Replies)
Discussion started by: koti_rama
4 Replies
Login or Register to Ask a Question