Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Dos2Unix file formater

by pschoonveld (Pilgrim)
on Apr 13, 2000 at 23:10 UTC ( #7516=snippet: print w/replies, xml ) Need Help??
Description: I hate DOS \r\n (carriage return, newline) file formats. Each line is all broken and crappy. So, I hacked up this little guy for my unix boxen around the world.
#!/usr/bin/perl
# convert a dos \r\n format to unix \bn
open (FILE, $ARGV[0]);
while (<FILE>) {
        # remove the stupid \r, replace with \n
        # some broken editors just put \r
        s/\r/\n/g;
        # Remove the duplicate \n
        s/\n\n/\n/g;
         print;
}
Couple comments:
This thing just dumps the data back to the screen. You need to capture it yourself. It is a preference for me because I many times don't want to overwrite the file I am editting. If you don't like this, change it.
Secondly, this thing does some crazy stuff. I hate blank lines. This thing makes sure there are none. Have code you want formatted nicely? It will break it in a manner that only vroom could understand. So, its quick N dirty to the max.

Update Chromatic offered an easier way to do this. In fact I am sure that is the better way to do it, and in fact at some point it was written similar to that. The hell if I rememeber why I changed it. But it basically came down to its origins and the fact I didn't want ANY blank lines.

Replies are listed 'Best First'.
RE: Dos2Unix file formater
by chromatic (Archbishop) on Apr 14, 2000 at 20:55 UTC
    Why not reduce that to: tr/\r\n/\n/s; Ahh, tr///!
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://7516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2023-03-29 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (70 votes). Check out past polls.

    Notices?