LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices

Reply
 
Search this Thread
Old 03-25-2013, 05:58 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Rep: Reputation: 46
A one-liner to get rid of carriage returns (\r) in a text file?


The file has only one (very long) line, an inheritance from the HTML where it came from.
 
Old 03-25-2013, 08:09 AM   #2
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
Problem solved. I edited with vim and ':s/\r//g'. Voila.
 
Old 03-27-2013, 01:19 AM   #3
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 272

Rep: Reputation: 51
Or this:

Code:
tr -d '\r' < oldfile > newfile
 
Old 03-28-2013, 03:41 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
True! I used tr all the time when posting, to eliminate newlines after editing with vim.
 
Old 03-28-2013, 04:53 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
There is also a handy dos2unix command.
 
Old 03-28-2013, 12:33 PM   #6
John VV
Guru
 
Registered: Aug 2005
Posts: 12,953

Rep: Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719
"dos2unix" and "unix2dos" comes in [v] VERY[/b] handy when going between MS windows and linux

however most editors like gedit and kate do this
and on the windows side SciTe dose this

Quote:
The file has only one (very long) line, an inheritance from the HTML where it came from.
did you use windows "notepad" for this ?

Last edited by John VV; 03-28-2013 at 12:34 PM.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed one-liner: search text in file and replace it. if not present, insert it pkramerruiz Programming 8 10-17-2010 09:49 AM
Remove New Line or Carriage return from Text File DIMonS Programming 13 10-01-2007 10:31 AM
Carriage Returns Thorkyl Linux - Software 7 06-28-2004 05:42 PM
XDrawString and carriage returns jpbarto Programming 1 03-25-2004 03:07 PM
Carriage Returns Trouble sancho5 Linux - General 2 08-29-2001 08:59 PM


All times are GMT -5. The time now is 11:20 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