VNR
April 9, 2009, 7:23am
1
$>cat file.txt
123 d3
234 abc 3
zyf 23
124 def 8
ghi kz0
...
...
I have the following output on the screen through <some command>.
$> <some command>
abc
def
ghi
...
...
I have to search for each of these patterns in the file.txt and print the lines in file.txt matching the output of <some command>.
I have tried to pipe it to grep like this
$> <some command> | xargs grep file.txt
But grep takes the pipe output as file and not as pattern.
Is there any way the output on STDOUT can be piped as pattern to grep or sed or awk without using a perl script.
Thanks & Regards
VNR
methyl
April 9, 2009, 8:11am
2
<some command>|while read SEARCH
do
grep "${SEARCH}" file.txt
done
VNR
April 9, 2009, 8:20am
3
Not able to identify SEARCH variable
Output is
SEARCH : Undefined variable
Btw I use csh
Thanks & Regards
VNR
egrep has (and some greps have) an option to read the patterns from a file.
If your OS (like Solaris) provides a mechanism to access
file descriptors as filenames, one can use this to read file descriptor 0 (stdin)
for the patterns.
<some command> | egrep -f /dev/fd/0 filename
VNR
April 9, 2009, 9:19am
5
nobody4:
egrep has (and some greps have) an option to read the patterns from a file.
If your OS (like Solaris) provides a mechanism to access
file descriptors as filenames, one can use this to read file descriptor 0 (stdin)
for the patterns.
<some command> | egrep -f /dev/fd/0 filename
Yeah this worked on the solaris machine. Thanks very much
VNR