1

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?

2
while read line
do
  sed 's#<REPLACE>#'"$line"'#g' infile.tmpl
done < numbers.dat
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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