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
Adding Multiple Lines to Multiple Files dayinthelife Shell Programming and Scripting 2 06-04-2008 11:50 AM
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 03:28 PM
Multiple search in multiple files maxvirrozeito Shell Programming and Scripting 2 12-13-2007 01:32 PM
Please Help. Need Help searching for multiple stings in a file and removing them. mjs3221 UNIX for Advanced & Expert Users 2 08-19-2006 06:28 AM
Searching for multiple criteria in log files? Relykk Shell Programming and Scripting 4 04-20-2004 02:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-06-2004
Anahka Anahka is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 4
Question Searching multiple files with multiple expressions

I am using a DEC ALPHA running Digital UNIX (formly DEC OSF/1) and ksh. I have a directory with hundreds of files that only share the extension .rpt. I would like to search that directory based on serial number and operation number and only files that meet both requirements to be printed out. I am new to scripting and have been try to do this with grep but have not had much luck.

here is a sample of the file: (120205462.rpt)
_________________________________
S/N: 10001 Name: ESSM GS Acceptance Operation: 300
-----------------------------------------------------
  #2 (permalink)  
Old 01-06-2004
viRaven viRaven is offline
Registered User
  
 

Join Date: Dec 2003
Location: The O.C.
Posts: 37
Try:

egrep
awk


do a man and see which one best suits your needs. I am partial to awk.
  #3 (permalink)  
Old 01-06-2004
Anahka Anahka is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 4
I am using egrep right now:

ser="10001"
oper="300"

egrep -l "$ser" *.rpt|egrep -l "$oper" *.rpt

this works but it also shows files that have an operation other then 300
  #4 (permalink)  
Old 01-06-2004
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Hmm.. I created two test files with
Code:
S/N: 10001                  Name: ESSM GS Acceptance                    Operation: 300
in one and
Code:
S/N: 10001                  Name: ESSM GS Acceptance                    Operation: 400
in the other.

When I ran your code, it only listed the first file with 300 in it. Are you sure the number 300 doesn't occur anywhere else in the files that don't have an operation code of 300? The same with the serial numbers I suppose... if you're searching for files with a serial number of 10001, you could end up displaying files with a serial number of 3010 but which have 10001 somewhere else in the file...

Last edited by oombera; 01-06-2004 at 03:28 PM..
  #5 (permalink)  
Old 01-06-2004
Anahka Anahka is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 4
I short handed the last bit of code because :

ser="S/N: 10001"
oper="Operation: 300"

I did this because there are chances of having 300 and 10001 in the collected data. using this and the egrep statement I get several operation 190's that have the serial number of 10001.
  #6 (permalink)  
Old 01-06-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Quote:
Originally posted by Anahka
I am using egrep right now:

ser="10001"
oper="300"

egrep -l "$ser" *.rpt|egrep -l "$oper" *.rpt

this works but it also shows files that have an operation other then 300
egrep -l "$oper" `egrep -l "$ser" *.rpt`
  #7 (permalink)  
Old 01-07-2004
Anahka Anahka is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 4
Using the above suggestion gives me an error.

grep: egrep -l "$ser" *.rpt: cannot open [No such file or directory]

anymore ideas.

Thanks Perderabo
Sponsored Links
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 06:30 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