LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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
 
LinkBack Search this Thread
Old 08-05-2010, 11:21 AM   #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, 11:31 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,361

Rep: Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910
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, 12:36 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 239Reputation: 239Reputation: 239
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 09:38 PM.

Main Menu
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