The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
handling null values in files ammu Shell Programming and Scripting 1 11-06-2007 04:43 PM
Help!! Need script to read files and add values by lines... dhuertas Shell Programming and Scripting 3 09-15-2007 11:14 PM
Need to find only unique values for a given tag across the files sudheshnaiyer UNIX for Dummies Questions & Answers 8 09-03-2007 12:53 AM
grepping lines out of files mariner UNIX for Advanced & Expert Users 2 09-24-2004 08:12 AM
Extracting values from files Master Error Shell Programming and Scripting 4 08-15-2004 09:23 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-15-2008
Sreejith_VK
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
grepping many values from same files

Hi All,

I am having a script in which I am greping some values and storing them from files with .err and .log extensions.
I feel I can do it better.But How?

Below is my piece of code.

Code:
oneerrors=`egrep -i -n "one" *.err *.log`
twoerrors=`egrep -i -n "two" *.err *.log`  
threeerrors=`egrep -i -n "three" *.err *.log | grep -v "threeException"`
fourerrors=`egrep -i -n "four" *.err *.log`
fiveerrors=`egrep -i -n "five" *.err *.log | grep -v "fivefile" | grep -v "five:"`
sixerrors=`egrep -i -n "six" *.err *.log`
sevenerrors=`egrep -i -n "seven" *.err *.log | grep -v "SREE_seven" | grep -v "SRE_seven" | grep -v "VALUE_seven" | grep -v "PRODUCT_seven"`
eighterrors=`egrep -i -n "eight" *.err *.log`
nineerrors=`egrep -i -n "nine" *.err *.log`
tenerrors=`egrep -i -n "ten" *.err *.log`
elevenerrors=`egrep -i -n "eleven" *.err *.log`
twelveerrors=`egrep -i -n "twelve" *.err *.log`
Can I put everything in a if loop or do something to optimize this piece of code?

Thanks to All.

Last edited by Sreejith_VK; 03-15-2008 at 09:01 AM..
  #2 (permalink)  
Old 03-15-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,523
Code:
awk 'BEGIN { 
     pat="one|two|four|five|six|eight|nine|ten|eleven|twelve"    
}
$0 ~ pat || (/three/ && !/threeException/ ) {print NR":"$0}
$0 ~ pat || (/seven/ && !/(SREE_seven|SRE_seven|VALUE_seven|PRODUCT_seven)/) {print NR":"$0}
$0 ~ pat || (/five/ && !/(fivefile|five:)/) {print NR":"$0}
' file
  #3 (permalink)  
Old 03-15-2008
Sreejith_VK
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Hi Ghost dog,

Thanks for your AWK code.
I am not so good at AWK.
Will I be able to store the results of each grep as in my code?

Last edited by Sreejith_VK; 03-15-2008 at 08:59 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0