Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to perform the following operation:

Given a file like this:

update FOO set STATUS="X" where ID=<REPLACE>;
insert into BAR (Z,W) values(<REPLACE>, 42);

And a file like this:


Give me a file with each line in the second file inserted in the <REPLACE> positions in the first, like this:

update FOO set STATUS="X" where ID=25478975;
insert into BAR (Z,W) values(25478975, 42);
update FOO set STATUS="X" where ID=65897895;
insert into BAR (Z,W) values(65897895, 42);

It probably won't take me too long to write a simple Python program to do this, but I strongly suspect I could do it by combining a few GNU/Linux commandline-tools in the right way. Can anyone show me how?

share|improve this question
up vote 2 down vote accepted
while read line
  sed 's#<REPLACE>#'"$line"'#g' infile.tmpl
done < numbers.dat
share|improve this answer
Exactly what I wanted. Thanks! – Rasmus Faber Sep 9 '10 at 6:26
Great! But how would I do this if I had more variables to change? – Dom Delimar Mar 9 '13 at 23:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.