In a normal case, sed
can edit the stream from another command simply by piping:
./somecommand | sed 's/xx/yy/g'
However, the sed
command I'm using is a little complex. Previously, I had gotten help with optimizing sed
for a specific use case:
Optimize shell script for multiple sed replacements
The eventual outcome was that for my use case, the following sed
command was the most optimal:
./somecommand > file
sed -e 's/^/s|/; s/$/|g/;' replacement_list | sed -r -f - -i file
Basically, the first sed
command creates a list of sed operations from a file with pairs of substitions. The second sed
command then uses the stream via piping and utilises the -f
option to process the file.
Things have changed a little since and now I've manage to get somecommand
to output results in stdout
instead of writing to a file, but I can't think of a way to rewrite the above set of commands correctly. Part of the difficulty is that the second sed
command is already using the stream from the first sed
command.
One thing I've tried is to assign the stdout
of somecommand
to a variable and attempt to <<<
it into the second sed
command. However, that didn't work.