Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Dos2Unix file formater by pschoonveld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found