brucezepplin
brucezepplin

Reputation: 9752

is it possible to prepend a string to output of cURL?

Looking at the man page for cURL:

-w, --write-out <format>

Make curl display information on stdout after a completed transfer. 

Where it is possible to use this flag and append a string to the output of cURL. However I can only get this to append to the end of the output of cURL, because as the man page suggests, the -w flag appends after a completed transfer.

so doing:

curl -sS "http:/somewebsite" -w "hello_world"

will produce:

$
contentfromcurl
hello_world

....well how do you get the output to be

$
hello_worldcontentfromcurl

i.e. is it possible to get -w to prepend rather than append?

thanks to @Adrian, this is the final answer -

curl -sS "http:/somewebsite" | xargs echo "mystring"

cheers!

Upvotes: 3

Views: 2319

Answers (2)

Mr. Llama
Mr. Llama

Reputation: 20899

If you're really desperate you can make a code block and include an echo. The following will have the output you're looking for:

{ echo -n "hello_world"; curl -sS "http:/somewebsite"; }

As for getting the -w option to prepend, the answer is no:

-w, --write-out
Make curl display information on stdout after a completed transfer. The format is a string ...

Upvotes: 3

Adrian Fr&#252;hwirth
Adrian Fr&#252;hwirth

Reputation: 45586

Is this what you are after?

$ printf "bar\nquux\n"
bar
quux

$ printf "bar\nquux\n" | sed 's#^#foo#g'
foobar
fooquux

Obviously, you would replace printf with your curl invocation.

But this seems a bit like an XY-problem - what are you trying to accomplish?

Upvotes: 1

Related Questions