What

Inserting text from a file after a pattern in a file.

Why

Its like copying and pasting for Linux on the command line.

How

Let’s take the following file which is missing the entire body of the message. We will call this file email.txt.

# email.txt

Hello,

Thanks,
Aaron Addleman

And let’s also take the following 3 files for our messages:

body1.txt

Thanks for signing up with our service! Instructions will follow after you confirm your email address...

body2.txt

Can you please fill out this short survey?

body3.txt

Sorry to see you leave our service! Was it because of our survey?

To make email messages from all of these messages, you can use the following (make sure to use double quotes around the sed command for evaluating the bash variable):

for a in `ls body*`; do sed "/Hello/ r $a" email.txt; done
comments powered by Disqus