SED and Solaris Append line to the end of File does not work

Hello,

I have to add a new line at the end of a File on Solaris-System:

I think my script should be right, because I evaluated it to other threads. However the script does not what I am expected it should do.

My file might look like this:

Line1
Line2
Line3 

And my script could look like this:

sed -e '/$ /a\
line4' test.txt

Remark: I also tried to write a\\ instead of a\

Could anyone help me solving this by using SED?

Thanks in advance

To append a line to the end of a file you can simply use:

echo "line4" >> test.txt

Yes, but I would like to know how it works by using SED under Solaris.

As bartus11 said, sed is unnecessary here. But, if you are learning to use sed and need to amuse yourself, fix your sed command as follows:

sed -e '$a\
line4' test.txt

This solution does not work under my Solaris-Implementation. It works under Linux and other Implementations.

What version of Solaris are you using? I just checked on Solaris 10 and it works just fine there.

Have you tried it as I had typed it? No slashes before/after the $ and use a \ before pressing Enter/return...

I exaktly typed it like this and it does not work, instead it deletes the last line from the existing file:

sed -e '$a\
line5' test.txt

---------- Post updated 05-07-12 at 08:29 AM ---------- Previous update was 04-07-12 at 10:05 PM ----------

Finally I figured out what the problem was.

The file I used was edited by windows and so the last line did not had
an UNIX End of Line (LF) instead an Windows End of LIne (CR+LF).
So SED was not able to detect the end of file.

Whenever you want to add an Line to the end of file using SED, this Script should be right:

sed -e '$a\
NEW Line' file.txt

If somebody got the problem and is transferring data via Windows watch out that line ends within UNIX-Standard, that is LF and not CR+LF.

---------- Post updated 06-07-12 at 03:55 AM ---------- Previous update was 05-07-12 at 08:29 AM ----------