The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
MySQL Tuning Tools with mysqltuner.pl and tuning-primer.sh Neo Web Programming, Web 2.0 and Mashups 1 4 Weeks Ago 07:49 AM
Searching word in a file with awk studieu Shell Programming and Scripting 3 07-09-2008 08:28 AM
Find Exactly word in grep command koti_rama UNIX for Dummies Questions & Answers 4 08-23-2007 03:52 AM
searching word in files naamas03 UNIX for Dummies Questions & Answers 2 11-06-2006 01:26 AM
Searching for key word within a file moradwan UNIX for Dummies Questions & Answers 1 03-07-2006 11:31 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
Registered User
 

Join Date: Aug 2008
Location: Chennai
Posts: 20
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 4 Weeks Ago
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,105
It's probably better if you post realistic examples and keep all the discussion in a single thread. See Please suggest some changes in my code and Guidance needed for quick script

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.
Reply With Quote
  #3 (permalink)  
Old 4 Weeks Ago
Registered User
 

Join Date: Aug 2008
Location: Chennai
Posts: 20
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.
Reply With Quote
  #4 (permalink)  
Old 4 Weeks Ago
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 883
If you really need to improve performance, you need to move away from a shell script
and write something in C or C++
Reply With Quote
  #5 (permalink)  
Old 4 Weeks Ago
Registered User
 

Join Date: Aug 2008
Location: Chennai
Posts: 20
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.
Reply With Quote
  #6 (permalink)  
Old 3 Weeks Ago
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,105
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.
Reply With Quote
  #7 (permalink)  
Old 3 Weeks Ago
Moderator
 

Join Date: Feb 2007
Posts: 1,666
You can give awk a try:

Code:
awk '{$0=tolower($0)}
/viewstatementbusinesslogic/ && /mycacommunicationexception/{c++}END{print c++}
' file
Regards
Reply With Quote
Google UNIX.COM
Reply

Tags
grep

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0