Melvin Melvin - 1 year ago 100
Bash Question

Execute shell command line by line from a file

I have a .txt file which has sed replace commands on each line and has 1000+ entries. The file is on my server.
Can any one please help me how to run the commands in file line by line and execute till the end of file.

My txt file looks like

sed -i 's|http://www.myoldsite/url/category/another/blah||g' ./db.sql
sed -i 's|http://www.myoldsite/url/category/blah/blah||g' ./db.sql
sed -i 's|http://www.myoldsite/url/category/blah||g' ./db.sql

Answer Source

You can convert your file to a list of substitution commands by removing all occurrences of sed -i ' and ' ./db.sql.

Using process substitution, the list can then be processed as a file passed to the sed -f option.

sed -i -f <(sed "s/[^']*'//;s/'.*//" file) ./db.sql
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download