Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I use the output of sed in another script?

For example (this doesn't work):

sed -n "$COUNTER",1p /domains.csv | wget

or

sed -n "$COUNTER",1p /domains.csv > /myScript.sh

As far as I know > lets me take the output and put it in a file, I'm just unsure of how to use this output as an argument in another script.

(I am aware I can declare the output as a variable, and then use it on the next line. I'm interested in how to do this as one "command")

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The | takes output and redirects it into stdin. wget needs a command line argument, not stdin so you want to pipe to xargs which will build a command line from stdin.

sed -n "$COUNTER",1p /domains.csv | xargs wget

Alternatively you can tell wget to take input on stdin

sed -n "$COUNTER",1p /domains.csv | wget -i -
share|improve this answer
    
Aha!! thanks so much, that'll do it. Thanks also for the explanation –  d-_-b Dec 29 '13 at 3:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.