user1301428
user1301428

Reputation: 1783

Send multiple outputs to sed

When there is a program which, upon execution, prints several lines on stout, how can I redirect all those lines to sed and perform some operations on them while they are being generated?

For example:

7zip a -t7z output_folder input_folder -mx9 > sed 's/.*[ \t][ \t]*\([0-9][0-9]*\)%.*/\1/'

7zip generates a series of lines as output, each including a percentage value, and I would like sed to display these values only, while they are being generated. The above script unfortunately does not work...

What is the best way to do this?

Upvotes: 1

Views: 289

Answers (1)

Didier Trosset
Didier Trosset

Reputation: 37447

You should use the pipe | instead of redirection > so that sed uses first command output as its input.

The above script line must have created a sed file in the current directory.

Furthermore, maybe 7zip outputs these lines to stderr instead of stdout. If it is the case, first redirect standard error to standard output before piping: 2>&1 |

Upvotes: 2

Related Questions