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
Convert file format from dos to unix
Convert file format by sed
$cp you-file-name your-file-name.bak $sed 's/^M//g' your-file-name.bak > your-file-name
Covert file format by Perl
$perl -i.bak -pe 's/^M//g;' your-file-name
Covert file format by vim
:setlocal ff=unix :wq