Computing.Net > Forums > Unix > replace a newline with string

replace a newline with string

Reply to Message Icon

Original Message
Name: raxit
Date: February 28, 2003 at 07:55:27 Pacific
Subject: replace a newline with string
OS: hpux
CPU/Ram: 133
Comment:

hi,
i need to add a string like /java at the end of each line in a file. i tried it using commands like tr '\012' '/java\012' but i think
tr command only replaces a character.
tried it using sed command ..but that also doesnt work.
please help.
thanks.


Report Offensive Message For Removal


Response Number 1
Name: neel
Date: February 28, 2003 at 08:19:51 Pacific
Subject: replace a newline with string
Reply: (edit)

can you try
sed 's/$/java$/g' File.EXT > file
I think it will work.


Report Offensive Follow Up For Removal

Response Number 2
Name: anukta_c
Date: February 28, 2003 at 08:21:58 Pacific
Subject: replace a newline with string
Reply: (edit)

Try
sed 's/$/\/java/g' yourfilename > newfile
-Anukta


Report Offensive Follow Up For Removal

Response Number 3
Name: neel
Date: February 28, 2003 at 08:24:18 Pacific
Subject: replace a newline with string
Reply: (edit)

Yeah .. missed the \/ part..
hey Ankuta dont you think we need to put java$ rather than java ?
~ Neel !!


Report Offensive Follow Up For Removal

Response Number 4
Name: anukta_c
Date: February 28, 2003 at 08:30:59 Pacific
Subject: replace a newline with string
Reply: (edit)

java$ will obviously work...but simply /java substitution will work as well. Though I cannot explain why. I will leave that to the Gurus of this forum.
-Anukta


Report Offensive Follow Up For Removal

Response Number 5
Name: anukta_c
Date: February 28, 2003 at 08:33:18 Pacific
Subject: replace a newline with string
Reply: (edit)


OOPS....sorry java$ substitution will not work...it will actually do a literal substitution with "java$".

-Anukta


Report Offensive Follow Up For Removal


Response Number 6
Name: raxit
Date: February 28, 2003 at 08:39:05 Pacific
Subject: replace a newline with string
Reply: (edit)

hey ,
anukta and neel..my problem is solved
thanks for your help.


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: replace a newline  with string

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software