LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2003, 05:11 AM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Sed - suitable to replace CR LF?


I would like to convert a regular WinDOS text file to unix text.

First I thought I could do it with sed, but it does not seem so:

sed s/.$//g # removes CRs, but also damages the file: it cuts off the last character of the last line, which never happens to be a CR
sed s/^M//g # does nothing, CRs remain in the file

Could you help me with a working sed example for this task?

Last edited by J_Szucs; 05-12-2003 at 05:12 AM.
 
Old 05-12-2003, 05:36 AM   #2
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,292

Rep: Reputation: 65
recent thread

http://www.linuxquestions.org/questi...138#post278138

another

http://www.linuxquestions.org/questi...551#post279551
 
Old 05-12-2003, 10:52 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
Some Distro's (at least Debian) include the dos2unix and unix2dos utilities especially for this.
 
Old 05-12-2003, 06:03 PM   #4
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Thanks for the tips.
tr -d '\015' worked!

Maybe sed would have worked, too, if I knew how to quote CR.
Now I know this might have worked: sed s/'\r'//g.
But I will not try it since I already have the solution using tr.
As for dos2unix: it was originally not on my system (an other kind of unix, not Linux); last year I downloaded it as a perl script, but it never seemed to work as expected.
 
  


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
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
Using sed to replace a lot of text Wynd Programming 9 10-07-2005 03:47 AM
Replace substring with SED marri Programming 2 07-09-2005 05:18 PM
SED;find and replace;help required gd13 Programming 3 12-21-2004 06:33 AM
[sed] replace string? chuanyung Programming 3 03-11-2004 08:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration