Results 1 to 6 of 6
Hi,
i have 3 files:- file1,file2,file3
file1 contains the data:- one
file2 contains the data:- two
file3 contains the data:- one two
can anyone help me how to find the ...
- 08-10-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
help required to find multiple strings in multiple files
Hi,
i have 3 files:- file1,file2,file3
file1 contains the data:- one
file2 contains the data:- two
file3 contains the data:- one two
can anyone help me how to find the file having the data 'one two' only using unix command
- 08-10-2011 #2Just Joined!
- Join Date
- Aug 2011
- Posts
- 11
for FILE in $(ls file*) ; do [ $(grep -c "one two" $FILE) -ne 0 ] && echo $FILE ; done
- 08-10-2011 #3Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
@theMickey
can u provide a generic command or script for my question?? for ex i have many files in a directory and i need to find the files having the strings given by the user, which may or may not be in the same line within a files
- 08-10-2011 #4Just Joined!
- Join Date
- Aug 2011
- Posts
- 11
Hm. Let's see, should be something like this:
Hope that helps.Code:#!/bin/sh # Search Strings S1="one" S2="two" # Directory where to search files DIR=. # Search subdirectories? SUBDIR=false # Do the real stuff $SUBDIR && MAXDEPTH="" || MAXDEPTH="-maxdepth 1" for FILE in $(find $DIR $MAXDEPTH -type f -print) ; do [ $(grep -c $S1 $FILE) -ne 0 -a $(grep -c $S2 $FILE) -ne 0 ] && echo $FILE done
- 08-10-2011 #5Just Joined!
- Join Date
- Aug 2011
- Posts
- 3
@theMickey
Thanks a ton..that was really helpful
- 08-10-2011 #6Just Joined!
- Join Date
- Aug 2011
- Posts
- 11
You're welcome.


Reply With Quote