Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

25478975
65897895

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

1 Answer 1

up vote 2 down vote accepted
while read line
do
  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

 
discard

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.