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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED and Solaris Append line to the end of File does not work
# 8  
Old 07-06-2012
I exaktly typed it like this and it does not work, instead it deletes the last line from the existing file:
Code:
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 ----------

Quote:
Originally Posted by Timo_HR
I exaktly typed it like this and it does not work, instead it deletes the last line from the existing file:
Code:
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.

Last edited by Timo_HR; 07-06-2012 at 08:55 AM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

2. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

3. Shell Programming and Scripting

Append the end of each line in a file with a given string

Hi friends, I have a file containing many lines as follows. M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\ADBasicView.java@@\main\v6.4.0_pit_a I would like to append the string "\0" at the end of each line in the file. The output should look... (10 Replies)
Discussion started by: nmattam
10 Replies

4. Shell Programming and Scripting

Append a string at the end of every line in a file

Hi Friends, I have a file with many lines as shown below. /START SAMPLE LINE/ M:\mmarimut_v6.4.0_pit_01\java\build.xml@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\port\Post.java@@\main\v6.4.0_pit_a M:\mmarimut_v6.4.0_pit_01\switchview\View.java@@\main\v6.4.0_pit_a /END SAMPLE LINE/ I... (1 Reply)
Discussion started by: nmattam
1 Replies

5. Shell Programming and Scripting

How can I append a string at the end of a line in a file

Hi, guys. I have one question: I have a file called "group", the contents of it is below: ******************************** ... test:x:203: sales:x:204: repair:x:205: research:x:206:brownj ... *********** Now I want to add string ",sherrys" at the end of "research:x:206:brownj", so... (5 Replies)
Discussion started by: daikeyang
5 Replies

6. Shell Programming and Scripting

Sed : identify a pattern and append a word at the end of a line

Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". I use the following command, but it deletes the term identified then adds the word. #sed... (4 Replies)
Discussion started by: dantares
4 Replies

7. Shell Programming and Scripting

sed append "\n" to end of every line in file

I know it sounds simple, but I want to e-mail the last 6 lines of a log file, which I have tailed into logresults.txt. I'm using echo -e "Subject:server results\nFrom:server log <user@domain.com>\n"`cat logresults.txt` | sendmail -t user@domain.com which works, but the body of the e-mail has... (4 Replies)
Discussion started by: unclecameron
4 Replies

8. Shell Programming and Scripting

Line Count and Append it to the end of the file.

Hi, I want to get a Line count of a file and append that at the end of the file. The Line count should not include the Headers : ------------------ COL1,COL2,COL3 123,abc,011 111,abd,0212 Record Count: 2 ------------------- Thanks. (7 Replies)
Discussion started by: smc3
7 Replies

9. Shell Programming and Scripting

Append text at end of the first line in a file

Hi I need to append some text @ end of the first line in a file. like myfile.txt list = a,b,c list.a=some.. I give the arg "d" . now it append at end of first line list=a,b,c,d list.a=some... Please help me out this (7 Replies)
Discussion started by: catgovind
7 Replies

10. UNIX for Dummies Questions & Answers

using sed to append text to the end of each line

Anyone know how to use SED to append a comma to the end of each line example: field1,field2,field3,field4 If i Cat /textfile ---- How can i append the end of /textfile with a comman? (8 Replies)
Discussion started by: Redg
8 Replies
Login or Register to Ask a Question