1tSurge
1tSurge

Reputation: 693

Filtering output from wget using sed

How would I go about taking the output from a post call made using wget and filtering out everything but a string I want using sed. In other words, let's say I have some wget call that returns (amongst part of some string) :

'userPreferences':'some stuff' }

How would I get the string "some stuff" such that the command would look something like:

sed whatever-command-here | wget my-post-parameters some-URL

Also is that the proper way to chain the two as one line?

Upvotes: 0

Views: 6088

Answers (3)

John B
John B

Reputation: 3646

If you are on a system that supports named pipes (FIFOs) or the /dev/fd method of naming open files, you could avoid a pipe and use < <(...)

sed whatever-command-here < <(wget my-post-parameters some-URL)

Upvotes: 0

timgeb
timgeb

Reputation: 78650

You want the output of wget to go to sed, so the order would be wget foo | sed bar

wget -q -O - someurl | sed ...

The -q flag will silence most of wget's output and -O - will write to standard output, so you can then pipe everything to sed.

Upvotes: 2

Lev Levitsky
Lev Levitsky

Reputation: 65781

The pipe works the other way around. They chain the left command's output to the right command's input:

wget ... | sed -n "/'userPreferences':/{s/[^:]*://;s/}$//p}" # keeps quotes

The filtering might be easier to express with GNU grep though:

wget ... | grep -oP "(?<='userPreferences':').*(?=' })" # strips the quotes, too

Upvotes: 0

Related Questions