AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  ^M Character on the end of all lines

    Posted Tue March 01, 2011 01:01 AM

    Originally posted by: Pharthiphan


    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
    #AIX-Forum


  • 2.  Re: ^M Character on the end of all lines

    Posted Tue March 01, 2011 03:28 AM

    Originally posted by: blanckea


    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
    #AIX-Forum


  • 3.  Re: ^M Character on the end of all lines

    Posted Fri May 27, 2011 03:20 PM

    Originally posted by: apeasecpc


    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
    #AIX-Forum