LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2010, 12:48 AM   #1
jdom
LQ Newbie
 
Registered: Nov 2010
Posts: 1

Rep: Reputation: 0
sed - Problem appending at the end of line


Hi,

Using sed, I am trying to append four commas ',,,,' at the end of lines containing the pattern 'Response' in a text file with lines such as these:

6,Pulse,50,254968,14886,NA,,,,
7,Picture,8,265157,0,1,15045,2,0,15000
7,Response,1,271553,6396,1
7,Pulse,50,274969,9812,NA,,,,
8,Picture,1,290232,0,1,15045,2,0,15000
8,Pulse,50,294969,4737,NA,,,,
8,Response,1,296837,6605,2
8,Pulse,50,314970,24738,NA,,,,
9,Picture,4,315307,0,1,15045,2,0,15000
9,Response,1,321090,5783,1
9,Pulse,50,334971,19664,NA,,,,
10,Picture,14,340382,0,1,15045,2,0,15000
10,Response,1,350102,9720,2

The script I am using for this is

sed -i '/Response/s/$/,,,,/'

However, when I run the scrip, the commas are appended in a new line inserted after the line with the pattern. When I open the modified txt file it looks like this:

6,Pulse,50,254968,14886,NA,,,,
7,Picture,8,265157,0,1,15045,2,0,15000
7,Response,1,271553,6396,1
,,,,
7,Pulse,50,274969,9812,NA,,,,
8,Picture,1,290232,0,1,15045,2,0,15000
8,Pulse,50,294969,4737,NA,,,,
8,Response,1,296837,6605,2
,,,,
8,Pulse,50,314970,24738,NA,,,,
9,Picture,4,315307,0,1,15045,2,0,15000
9,Response,1,321090,5783,1
,,,,
9,Pulse,50,334971,19664,NA,,,,
10,Picture,14,340382,0,1,15045,2,0,15000
10,Response,1,350102,9720,2
,,,,

Any idea what's wrong here and how to get the desired result?

Many thanks

Last edited by jdom; 11-05-2010 at 12:49 AM. Reason: Spaces between lines were automatically inserted
 
Old 11-05-2010, 01:21 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
The command you gave worked fine on my end.

Could it be a line ending problem? That is, are you trying to modify a Windows file (which uses different line endings than Linux)? That might explain it.

Alternatively, you can try this version of the command:
Code:
sed -i '/Response/s/\(.*\)/\1,,,,/' data_file
Where "data_file" should be replaced with your appropriate filename.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed - How do you replace end of line with a space pppaaarrrkkk Programming 7 02-07-2011 11:27 AM
sed add a character to the end of each line keenboy Linux - General 2 08-05-2010 12:36 PM
sed mathing at the end of line by the beging of the next sqn Programming 9 02-18-2010 08:10 AM
[SOLVED] sed: How to remove the end of a line? angel115 Programming 2 10-01-2007 10:29 AM
[SOLVED] delete the end of each line in a file with sed angel115 Linux - Newbie 3 11-16-2005 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration