This smells like a homework question. If it isn't what is the "real world problem" of your question and what have you done to attempt to solve this problem yourself?
I have never used sed before, i tried searching on google but of no avail, i know it has a very simple solution for someone who has already used sed......
I have never used sed before, i tried searching on google but of no avail, i know it has a very simple solution for someone who has already used sed......
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.