Reputation: 693
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
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
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
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