DomainsFeatured DomainsFeatured - 10 months ago 61
Linux Question

How To Prepend Variable Pattern By Piping Grep Output To Sed?

I have the following data in two files:



Using the following command (I'm using this structure because usually there is more in the files and this is just a minimal example):

cat domains.txt | while read LINE; do grep -m 1 "$LINE" urls.txt

This will give me the matching line.

However, I would like the desired output to be:,

I would like to add a pipe that would prepend the
variable before the matched output. I was thinking something with
should be easy? Your input is highly appreciated.


Although this is easy with
, if someone has an answer with piping the output, I would like to use that to go with the script.

Answer Source
while IFS= read -r line; do echo -n "$line,"; grep -m 1 "$line" urls.txt; done < domains.txt