[Solved] Append text to each of multiple lines in file


Use something simple like sed:

sed -r 's/^([0-9]*)$/update "table1" set event_type = \'NEW\' where id=\1/' file
               |     write back using \1 as placeholder
             catch digits in the file

Previous answer

I used an approach based on bash loops, whereas it is a bit overkilling. See a related question: Why is using a shell loop to process text considered bad practice?

Loop like this:

while read id
do
   echo "update \"table1\" set event_type="NEW" where id=${id};"
done < ids.txt

It outputs:

$ while read id; do echo "update \"table1\" set event_type="NEW" where id=${id};"; done < ids
update "table1" set event_type="NEW" where id=10003;
update "table1" set event_type="NEW" where id=10009;
...
update "table1" set event_type="NEW" where id=79345;
update "table1" set event_type="NEW" where id=79356;

12

solved Append text to each of multiple lines in file