Experience: is what you get soon after you need it.

Experience: is what you get soon after you need it.

Rasul Allah (sal Allahu alaihi wa sallam) said: "Restore the trusts of those who trust you, and deal not falsely with him who deals falsely with you." [Abu Dawud, Tirmidhi]

Search This Blog

Monday, May 17, 2010

Remove ^M character from UNIX

To remove ^M characters in UNIX

To get the ^M in unix ( press control+V control+m ) i.e ctrlv & ctrlm on your keyboard(no spaces in between)

do anyone of the following:

dos2unix filename ( not all unix flavors have dos2unix by default)

or
sed 's/^M//g' ${INPUT_FILE} > tmp.txt
mv tmp.txt ${INPUT_FILE}

or
tr -d "\15" < ${INPUT_FILE} > tmp.txt;
mv tmp.txt ${INPUT_FILE}

or

perl -p -i -e 's/^M//g' ${INPUT_FILE}
or

multiple files in a directory

This will remove all the ^M from each file.
perl -p -i -e 's/^M//g' *