I have the following code:cat file | grep example | sed 's/http/https/' >> report.txtOutput of that command: https://example.com/page/index.htmlThis will add a link, with HTTPS, to the file. I would like, however, for that same output to also replace URL in a second file. Content of the second file:TEXT TEXTTEXTURLTEXT TEXTDesired change in second file:TEXT TEXTTEXThttps://example.com/page/index.htmlTEXT TEXTIs this possible?P.S.: I can't repeat the command again, as it is actually not a simple cat but an upload process that starts the command.
Using tee to append string to a file and also use it as replacement for a pattern in another file
awk;sed;tee
For the record, you don't need cat and grep as sed alone can do it:sed '/URL/!d;s/http/&s/'Anyway, assuming you run a chain of commands that produce a single line of output you can do: ... | tee -a report.txt | sed 's|[\&/]|\\&|g;s|.*|s/URL/&/g|' | sed -f- -i infile.jsonThis appends the output to report.txt but also pipes it to sed which turns it into a sed command which is then piped to another sed which will edit the .json file in-place.