Quote:
Originally Posted by
gaurav_1711
i tried..
sed "s/^/prefix/;s/\n/sufix/" oldfile > newfile
but it is only adds the prefix...
The reason is that there is no "\n" at the end of the line as far as sed is concerned. There is a far more easy device to match line ends or line beginnings, which you have already seen used here:
"^" at the beginning of a regex means "line beginning". "x" finds any x, "^x" finds only an "x" on first position of the line.
"$" at the end of a regex means "line end". "x$" would match only a line ending with "x".
There is another metacharacter you have seen used here: "&" in a replacement string this means "everything that has been matched by the regex". Example:
echo "xxxabcxxx" | sed 's/abc/y&y/' ==> will give "xxxyabcyxxx"
echo "xxxabcxxx" | sed 's/ab/y&y/' ==> will give "xxxyabycxxx"
You should now be able to create a correct sed script yourself. In fact you have two ways of doing it shown here.
I hope this helps.
bakunin