:%s/^V^M//g

Remove ^M characters at end of lines in vi

Whereas ^V is CTRL-V. converts a dos file to unix by removing 0x13 characters
Sample Output
before:
    function __construct($livraison=NULL)^M
    {^M
        if (is($livraison) && trim($livraison) != '') {^M
            $this->id = $livraison;^M
        }^M
        $this->vide = true;^M
    }^M
after:    function __construct($livraison=NULL)
    {
        if (is($livraison) && trim($livraison) != '') {
            $this->id = $livraison;
        }
        $this->vide = true;
    }

-1
By: slim
2009-08-19 11:59:22

These Might Interest You

  • Filter out lines of input that contain 72, or fewer, characters. "sed -n" : don't print lines by default "/^.\{73,\}/" : find lines that start with 73 (or more) characters "p" : print them Show Sample Output


    0
    sed -n "/^.\{73,\}/p" < /path/to/file
    flatcap · 2014-03-20 12:31:57 0
  • Filter out lines of input that contain 72, or fewer, characters. This uses bash only. ${#i} is the number of characters in variable i. Show Sample Output


    1
    while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
    flatcap · 2014-03-20 12:27:06 0
  • Per default, linux/unix shells are configured with a width of 80 characters. If you like to edit a phrase or string on a line with more than 80 characters it might take long to go there (for example a line with 1000 characters and you like to edit the 98th word which is character 598-603). Maybe you might wish to use 78 characters, because if you forward the text via mail and the text will be quoted (2 extra characters at the beginning to the line "> "), you use 80 characters, otherwise 82, which are lame.


    3
    fold -w 78 -s file-to-wrap
    GeckoDH · 2009-05-19 19:33:10 1
  • Remove blank lines from files, even if some of the lines have whitespace (spaces, tabs, etc.). Also creates a .bak copy of the original file. Works on Mac also. Thanks to those all those who left comments. Show Sample Output


    0
    sed -i.bak '/^[[:space:]]*$/d' file_name
    Highwayman · 2009-04-07 11:32:06 4
  • With thanks to dew on Efnet's #regex, back in 2005. This version indents subsequent lines after the first by one space, to make paragraphs visibly obvious -- remove the \3 to prevent this behavior. Lines are only broken at spaces: long strings with no spaces will not wrap, so URLs are safe. Replace the "75"s to make the regex linewrap to other amounts. From the unix commandline, "fold" is likely your better choice, but this snippet is handy in editors which allow regular expressions, in scripting, and other such situations where "fold" is unavailable. Show Sample Output


    0
    s/(?=.{75,})(?:(.{0,75})(?:\r\n?|\n\r?)|(.{0,75}))[ ]/\1\2\n /g
    DewiMorgan · 2012-02-28 02:27:20 0
  • Modify file in place to remove empty lines and create a backup of the original with the extension .bak Show Sample Output


    4
    sed -e '/^$/d' -i .bak filewithempty.lines
    donnoman · 2011-03-24 00:03:25 0

What Others Think

Or even: flip -u filename
dopeman · 456 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: