Paul - The Programmer

simple & stupid

Add prefix and append suffix to each line of text file

I need to update one text file to add prefix and suffix to each line. For instance, let's say the text file I need to update is like:

line-number-one
line-number-two
line-number-three

I want the file be updated as below.

prefix line-number-one suffix
prefix line-number-two suffix
prefix line-number-three suffix

Here are my solutions.

To update with vim:

:%s/.*/prefix & suffix/g

To update with sed:

$ sed 's/\(.*\)/prefix $1 suffix/' sample-file.txt

To update with awk:

$ awk '{ printf( "prefix %s suffix\n", $1 ); }' sample-file.txt