Home > Blockchain >  How to remove ^M characters from file in aix?
How to remove ^M characters from file in aix?

Time:08-19

I have tried following commands, but they don't work. sed isn't installed and hence doesn't work. Same goes for dos2unix.

awk 'sub(/^M/,"")' finename

cat finename | sed 's/^M//’ > finename

awk '{sub(/^M/,"")}1' finename > finename

tr -d $'\r' < finename

tr -d '\015' < finename > finename

awk 'sub(/^M/,"");1' finename

CodePudding user response:

This command worked : tr -d '\r' < filename > new_file

CodePudding user response:

The easiest way is the dos2unix way. In case it's not installed, you might try this:

sudo apt install dos2unix

In case the installation of dos2unix is not permitted, you might try the following command:

sed 's/\r//' input > output

If sed is not working too, you might go for the following awk solution:

awk '{sub(/^M/,"")}1' input > output

(Afterwards you just rename output back to input)

CodePudding user response:

if the file hasn't been pre-mangled by cat into caret notation of "^M" for \r, one could try

{m,n,g}awk 3 ORS= RS='\r' 

if it has already been mangled,

gawk -Pe/-ce NF=NF OFS= FS='[\\^]M' # these 2 gawk modes act up; 
                                    # switching to FS instead of RS
gawk/nawk    6     ORS= RS='\\^M' 
mawk         9     ORS= RS='\^M'
  • Related