removing ^m char

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anutosh100
    New Member
    • Mar 2008
    • 8

    removing ^m char

    I have uploaded one txt file from windows to unix.when i am opening the file
    in vi editor at the end of every line it is giving ^m char.

    can any one tell me what is the procedure to remove ^m char from my txt file.

    Regards
    Anutosh
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Well, you could just remove it with vi, but I'm guessing it's not only on this file or the file is very big?
    In that case, you could try the following bash script:
    Code:
    while read line; do echo "${line%%^m}"; done < <(cat file.txt) > new_file.txt
    (file.txt being your old file and new_file.txt being the new one)

    Hope it works.

    Greetins,
    Nepomuk

    Comment

    • mac11
      Contributor
      • Apr 2007
      • 256

      #3
      you probably have a utility called dos2unix on your unix machine which will do that for you

      google found this summary page for me, but you can probably just run man for it yourself

      Comment

      • fordie1000
        New Member
        • Mar 2008
        • 32

        #4
        Originally posted by mac11
        you probably have a utility called dos2unix on your unix machine which will do that for you

        google found this summary page for me, but you can probably just run man for it yourself
        http://linux.about.com/od/commands/l...l1_dos2uni.htm
        If you just want to do this while vi is open ...

        You can just do this :

        1. open file in vi
        2. type this --> :%s/<Ctrl+V><Ctrl+M >// ----> then hit Enter

        Where the <Ctrl+V> command is ... hold the Ctrl button and press the V key
        and the same goes for the <Ctrl+M> command.

        The <Ctrl+V> command will insert this character '^'
        The <Ctrl+M> command will insert the 'M' character (which stands for a carraige return in dos)

        Comment

        • gpraghuram
          Recognized Expert Top Contributor
          • Mar 2007
          • 1275

          #5
          i think dos2unix is the best option for this.

          Raghu

          Comment

          Working...