Topic
  • 2 replies
  • Latest Post - ‏2011-05-27T19:19:51Z by apeasecpc
Pharthiphan
Pharthiphan
12 Posts

Pinned topic ^M Character on the end of all lines

‏2011-03-01T06:00:33Z |
Hi All,

while opeing a text file via vi after doing a ftp or scp from linux or windows using bin mode.

Im getting a ^M Character on the end of all lines.

Please help

Regards,
Pharthiphan
Updated on 2011-05-27T19:19:51Z at 2011-05-27T19:19:51Z by apeasecpc
  • blanckea
    blanckea
    12 Posts

    Re: ^M Character on the end of all lines

    ‏2011-03-01T08:27:49Z  
    Hello,
    You should transfer text files in Ascii mode, or the conversion is not done.
    If files are already on AIX and you want to remove the ^M you can use :
    sed -e "s/^M//g" file1 > file2
    On the command line the ^M in the sed command must be donne using : <ctrl>+V then <enter key>.
    Regards
  • apeasecpc
    apeasecpc
    2 Posts

    Re: ^M Character on the end of all lines

    ‏2011-05-27T19:19:51Z  
    Since AIX does not have the dtox or xtod commands provided in other types of UNIX, I created simple awk scripts to replicate them.

    dtox:
    #!/bin/ksh
    #dtox
    awk '{T=$0;if(length($0)>0) {if((substr($0,length($0),1)=="\r")&&(length($0)>1))
    T=substr($0,1,length($0)-1);if((substr($0,length($0),1)=="\r")&&(length($0)==1)
    ) T="";}printf("%s\n",T);}' $1

    xtod:
    #!/bin/ksh
    #xtod
    awk '{T=$0;if(length($0)>0) {if((substr($0,length($0),1)=="\r")&&(length($0)>1))
    T=substr($0,1,length($0)-1);if((substr($0,length($0),1)=="\r")&&(length($0)==1)
    ) T="";}printf("%s\r\n",T);}' $1

    =>dtox {source} >{destination) - strips ^M character
    =>xtod {source} >{destination} - adds ^M character back in