tc13 tc13 - 8 months ago 59
Linux Question

Using sed replace line in file with another file

I have a very large tab delimited file, I would like to replace a single line in this file with another. As the line has >100 columns, a simple sed 's/find/replace/' is not desirable. My newline is stored in file newline.txt

How do I achieve:

sed 's/find/newline.txt/' infile


From @Aaron

sed "s/^.*find.*$/$(cat newline.txt)/" infile.txt

Where find is a unique string in infile.txt that returns a single line, the line is then replaced by newline.txt