pipe | question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pipe | question
# 1  
Old 06-07-2007
pipe | question

how do you pipe the results to next statement as argument?

somecommand | grep $result somefile

how do you reference $result with??
# 2  
Old 06-07-2007
Please read the xargs manpage.
# 3  
Old 06-08-2007
I did and that doesn't seem to help me..

command | xargs grep file

this does not work
# 4  
Old 06-08-2007
1. xargs normally appends the arguments to the command

2. looks like you need it (a) to be the first argument (b) only one argument per iteration, for (b) try the -n 1 xargs switch.
# 5  
Old 06-08-2007
no luck..

I am suprised that there is no easy way to do this??

[root@rleeserver tmp]# cat yahoo
now
[root@rleeserver tmp]# cat yahoo2
never
now
never
[root@rleeserver tmp]# cat yahoo | xargs grep yahoo2
grep: now: No such file or directory
[root@rleeserver tmp]# cat yahoo | xargs -n 1 grep yahoo2
grep: now: No such file or directory
# 6  
Old 06-08-2007
Not sure whether this is what you want?

Code:
[bernardchan@bernardchan shm]$ cat yahoo | xargs -i{} grep {} yahoo2
now

# 7  
Old 06-08-2007
that is really koo and it SHOULD have been what i have been looking for. but.. one unfortunate thing si, i am not running grep.. i am running a awk program.. and it is not liking the argument too much..

this is the awk program i am running

#!/bin/bash
file=$1
name=$2
awk 'BEGIN {FS="\n"; RS=""; ORS="\n\n"}
{if (NF==1) hdrvar=$0; else if ($0~/'$file'/) print hdrvar,"\n",$0 }' $name


so, it does not like the option too much.. but that is very nice to know though
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

2. UNIX for Dummies Questions & Answers

xargs vs. pipe

I have been using unix on and off for a number of years. I am not a sys admin. I use what I need. I have googled this, but I really can't figure out what is the difference between using xarg and just using a regular pipe? Why do I need to include xarg sometimes and how do I know when I need it? (2 Replies)
Discussion started by: guessingo
2 Replies

3. Programming

Newbie question on exec,fork, wait,pipe C

Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine. So, i want to... (1 Reply)
Discussion started by: Cuervo
1 Replies

4. Shell Programming and Scripting

Replace pipe with Broken Pipe

Hi All , Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies

5. Shell Programming and Scripting

How can I use pipe

Hi, guys: I am working on my shell using c. How can I use pipe to implement the following? ls -l 1>> | grep hellp 1<< 2>> | less 2<< (the output of ls goes to grep, and the output of grep goes to less) Thanks Please use and tags when posting code, data or logs etc. to preserve... (1 Reply)
Discussion started by: tomlee
1 Replies

6. UNIX for Dummies Questions & Answers

BASH Pipe question

Hi all, I'm new to shell scripting, but enjoying myself! :cool: I'm trying to execute the following statement: alias evol="ps -AH | grep evol | cut -d' ' -f2 | kill -9" As you might guess. I'm wanting to use a single command 'evol' to kill all the processes containing the phrase 'evol' ... (4 Replies)
Discussion started by: mgrahamnz
4 Replies

7. Shell Programming and Scripting

Pipe filtering

Hi, The thing is that sometimes I need to filter an arbitrary output given a condition (think on the "filter" function present on some programming languages) from the shell (I use sh/bash). I tried this: #!/bin/sh # Usage: filter command COMMAND=$1 shift 1 xargs "$@" -I "{}" sh -c "if... (3 Replies)
Discussion started by: tokland
3 Replies

8. UNIX for Dummies Questions & Answers

Named PIPE

Gurus, I've a File Transaction Server, which communicates with other servers and performs some processing.It uses many Named PIPE's. By mistake i copied a named PIPE into a text file. I heard that PIPE files shouldn't be copied.Isn't it? Since it's a production box, i'm afraid on... (2 Replies)
Discussion started by: Tamil
2 Replies

9. UNIX for Dummies Questions & Answers

Question in reference to the pipe |

My question is can you use the pipe more than one time in the same command line? By the way I am new to UNIX. Thanks in advanced! (3 Replies)
Discussion started by: elkoreanopr
3 Replies

10. Programming

pipe help

i made a lot of processes. here is the code: main() { printf("\nEnter K="); scanf("%d",&k); printf("Enter L="); scanf("%d",&l); printf("\nFather id=%d\n",getpid()); x=0; makechild(); sleep(2); return 1; } int makechild() { for(q=1;q<=k;q++) { if(f=fork()) { ... (5 Replies)
Discussion started by: bb666
5 Replies
Login or Register to Ask a Question