Piping STDOUT as pattern to grep or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Piping STDOUT as pattern to grep or sed
# 1  
Old 04-09-2009
Piping STDOUT as pattern to grep or sed

$>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
# 2  
Old 04-09-2009
<some command>|while read SEARCH
do
grep "${SEARCH}" file.txt
done
# 3  
Old 04-09-2009
Not able to identify SEARCH variable


Output is
SEARCH : Undefined variable

Btw I use csh

Thanks & Regards
VNR
# 4  
Old 04-09-2009
Re: Piping STDOUT as pattern to grep or sed

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
# 5  
Old 04-09-2009
Quote:
Originally Posted by 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

2. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

3. Shell Programming and Scripting

Sed/awk : to grep only required pattern disk

Hi Experts, Need help with the following: Desired output: Only want to get the output marked in green. The file: --- Physical volumes --- PV Name /dev/disk/disk4704 PV Status available Total PE 6399 Free PE ... (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

How to print the lines between the pattern using awk/grep/sed?

Hi, I need a help to search a pattern and print the multiple lines between them. Input file: Tue May 29 12:30:33 EDT 2012:threadWebContainer : 357:com.travimp.hotelierlinks.abba.service.RequestHandler.requestService(String, ITICSDataSet): hotelCancelReservation request: ... (4 Replies)
Discussion started by: aroragaurav.84
4 Replies

5. UNIX for Dummies Questions & Answers

One liner pattern search with awk/sed/grep

I have an array containing bunch of characters. I have to check this array for specific character and if "Not Found than" use a goto statement to go to USAGE set options = (A B C D E F) @ i = 0 while ($i <= ${#options}) if ($options != "F" || $options != "D") then goto USAGE endif @... (1 Reply)
Discussion started by: dixits
1 Replies

6. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies

7. Shell Programming and Scripting

SED equivalent for grep -w -f with pattern having special characters

I'm looking for SED equivalent for grep -w -f. All I want is to search a list of patterns from a file. Also If the pattern doesn't match I do not want "null returned", rather I would prefer some text as place holder say "BLANK LINE" as I intend to process the output file based on line number. ... (1 Reply)
Discussion started by: novice_man
1 Replies

8. Shell Programming and Scripting

How to awk/sed/grep lines which contains a pattern at a given position

Dear friends I am new to linux and was trying to split some files userwise in our linux server. I have a data file of 156 continuous columns named ecscr final. I want the script to redirect all the lines containing a pattern of 7 digits to separate files. I was using grep to do that,... (2 Replies)
Discussion started by: anoopvraj
2 Replies

9. Shell Programming and Scripting

Extracting pattern only with AWK | SED | GREP

We have the following statement working in CGYWIN, but when we move the program to Solaris 10 it fails. x=`echo "ABC196925XYZ" | grep -o --only-matching "\{6\}"` How can we use AWK or SED to extract only the number from the string? The following outputs the entire string. We only want... (5 Replies)
Discussion started by: James Clark
5 Replies

10. Shell Programming and Scripting

grep and sed to find a pattern and add newline

Hello All, I have log file the result from a multithreaded process. So when a process finishes it will write to this log file as 123 rows merged. The issue is sometimes the processess finish at the same time or write to the file at the same time as 123 rows merged.145 rows merged. At... (5 Replies)
Discussion started by: ssikhar
5 Replies
Login or Register to Ask a Question