Solved

How to delete/convert conrol character (LF,CR) from text file ?

Posted on 2009-04-04
5
743 Views
Last Modified: 2012-05-06
Windows and DOS uses a pair of CR and LF characters to terminate lines. UNIX (Including Linux and FreeBSD) uses an LF character only. The Apple Macintosh  uses a CR character only.

can some one let me know how to convert text file and delete the control character form text file?
I got to know only how to convert windows text file in unix, and that is perl -i.bak -pe "s/\r//g" file as shared by ozo in my previous post.

Can some one give me perl one-liner to do all the appropriate conversion in text file between hardware platform?
0
Comment
Question by:beer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 4

Accepted Solution

by:
blissbear earned 250 total points
ID: 24070210
dos to unix:
perl -i.bak -pe "s/\r//g"

unix to dos:
perl -i.bak -pe "s/\n/\r\n/g"

mac to unix:
perl -i.bak -pe "s/\r/\n/g"

unix to mac:
perl -i.bak -pe "s/\n/\r/g"

mac to dos:
perl -i.bak -pe "s/\n/\r\n/g"

dos to mac:
perl -i.bak -pe "s/\n//g"
0
 
LVL 4

Expert Comment

by:blissbear
ID: 24070214
the regex expression s/x/y/ will replace the x string with y.
0
 
LVL 4

Expert Comment

by:blissbear
ID: 24070219
on a side note be careful you know what format you are converting from.

If you run dos->mac and then dos->unix on the same data stream you are going to end up stripping all the CR and LF characters.
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24071474
Linux has a command just for this:

dos2unix oldfile.txt > newfile.txt

0
 

Author Closing Comment

by:beer9
ID: 31566702
Thanks! :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question