tc13 tc13 - 1 year ago 120
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download