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
problem with grep on search string in a txt file over multiple files m00 UNIX for Dummies Questions & Answers 2 05-18-2008 02:21 PM
Need to search and replace in multiple files in directory hierarchy umen Shell Programming and Scripting 3 12-24-2007 04:56 AM
Search for files in multiple directories ravikirankethe UNIX for Dummies Questions & Answers 7 10-29-2006 05:29 PM
Searching multiple files with multiple expressions Anahka Shell Programming and Scripting 6 01-07-2004 06:24 PM

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 12-13-2007
maxvirrozeito maxvirrozeito is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 10
Multiple search in multiple files

Hello,

I would like to perform a search of several different strings in different files. I have the ouput of a unix command X which is for instance:

aaa
bbb
ccc

and I would like to look for each of these three strings into several files: file1 file2 etc.

I have come up with a solution that works... but slowly and not very neatly..
I am redirecting the output I get from command X to a file and then I read this file line by line performing the search with grep:

Code:
[several commands] > tmpFile
while read line
do
grep $line file1 file2 file3 >> finalFile
done < tmpFile
is it possible to avoid the loop by piping the output of X to a sed command for ex ?

Thank you for any help
Max
  #2 (permalink)  
Old 12-13-2007
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Use something like:

Code:
command |xargs -i ksh -c 'grep {} file'
  #3 (permalink)  
Old 12-13-2007
maxvirrozeito maxvirrozeito is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 10
That's perfect !!!!

Thanks a lot

Max
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 05:41 PM.


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