Multiple search in multiple files

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple search in multiple files
# 1  
Old 12-13-2007
Multiple search in multiple files


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:


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:

[several commands] > tmpFile
while read line
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
# 2  
Old 12-13-2007
Use something like:

command |xargs -i ksh -c 'grep {} file'

# 3  
Old 12-13-2007
That's perfect !!!!

Thanks a lot

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. Shell Programming and Scripting

Pattern search multiple files

#!/usr/bin/ksh a="Run successfully" cd $APPS ls -l *.txt | while read $txt do if then cp $APPS/$txt cp $hist/$txt else rm $APPS/$txt echo "Files has been removed" fi done New in shell script please help me out Around 100 txt files in $APPS dir i want to search pattern from... (8 Replies)
Discussion started by: Kalia
8 Replies

3. Shell Programming and Scripting

Search for multiple files

I need to look for 3 files in a particular directory, if they are > 0kb. If files exist proceed further, if not mail out saying one of the file is missing. All the 3 files should be present. Please see my script below and correct if needed. Anyway, it is not working. #! /bin/bash... (13 Replies)
Discussion started by: Radfelder
13 Replies

4. Shell Programming and Scripting

Search/Replace in multiple files recursively

Hi there, I am using AIX and trying to search and replace a string with another string in multiple files in different directories. I wanted to search replace in steps so I don't change all of the instance anywhere in the server at once, minimizing impact. STEP 1: -------- I first searched... (5 Replies)
Discussion started by: zaino22
5 Replies

5. Shell Programming and Scripting

Search and Replace in multiple files

Hello, I have hundreds of files in which I need to change email address. Here is what I am trying to do: 1. All text files are in a directory "a" 2. In the text file, I want to replace email address for preparer. All these lines start with {{PreparerEmail and end with }}. The email... (3 Replies)
Discussion started by: cartrider
3 Replies

6. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

7. Solaris

How to search for a word in multiple files

Hi, I want to find for a particular word which is existing in different files and folders under the parent directory. What command can I use to retrieve all the file names which is having the word. (1 Reply)
Discussion started by: rogerben
1 Replies

8. Shell Programming and Scripting

Search multiple patterns in multiple files

Hi, I have to write one script that has to search a list of numbers in certain zipped files. For eg. one file file1.txt contains the numbers. File1.txt contains 5,00,000 numbers and I have to search each number in zipped files(The number of zipped files are around 1000 each file is 5 MB) I have... (10 Replies)
Discussion started by: vsachan
10 Replies

9. Shell Programming and Scripting

Multiple search string in multiple files using awk

Hi, filenames: contains name of list of files to search in. placelist contains the names of places to be searched in all files in "filenames" for i in $(<filenames) do egrep -f placelist $i if ] then echo $i fi done >> outputfile Output i am getting: (0 Replies)
Discussion started by: pinnacle
0 Replies

10. UNIX for Dummies Questions & Answers

Search for files in multiple directories

I want to search for a file pattern in more than one directory. How I need to do that? Here is the scenario: I am having a directory structure like the following: /log ...../20051001 ..........ftp_server_20051001.log ..........ftp_down_server.log ..........ftp_up_server.log... (7 Replies)
Discussion started by: ravikirankethe
7 Replies
Login or Register to Ask a Question