LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 08-05-2010, 12:21 PM   #1
keenboy
Member
 
Registered: Jan 2008
Location: Cullompton
Distribution: Kubuntu
Posts: 36

Rep: Reputation: 15
sed add a character to the end of each line


I am using the following command to add a comma to the end of each line in my file:

sed 's/$/,/' myfile

but for some reason the comma gets placed on a new line in between each line in the file.

Why is this?
 
Old 08-05-2010, 12:31 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
That's really strange. Maybe there is some weird hidden character at the end of each line. Is this a file created in Win/DOS environment? Please, post the output of the following command (using CODE tags)
Code:
head -n1 myfile | od -c
this should tell us if there is something strange in the first line of the file.
 
1 members found this post helpful.
Old 08-05-2010, 01:36 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
dos2unix myfile
sed 's/$/,/' myfile
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed help - replace line feed with different character bradvan Programming 7 04-23-2012 12:31 AM
removing new line character using sed Fond_of_Opensource Linux - Newbie 4 03-26-2010 03:19 PM
Error: junk at end of line, first unrecognized character is `,' chenxunuo Linux - Embedded & Single-board computer 0 05-08-2008 11:24 AM
end of line character hyperriven Linux - General 1 04-07-2004 09:24 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


All times are GMT -5. The time now is 02:28 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration