Insert a string before or after each line of a file
Submitted by madvip on Fri, 01/11/2008 - 10:55.
Let's say you have a list of tables inside a text file called e_tables.txt and you want to generate an SQL file to drop these tables. With sed this is a very easy task to do:
sed -e 's/.*/DROP TABLE & CASCADE CONSTRAINTS;/' e_tables.txt
The code can be interpreted as follows. The ".*" tells sed to match every line and replace it with strings "DROP TABLE", "CASCADE CONSTRAINTS" and the matched line, denoted by "&".

