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

Wednesday, July 13, 2011

remove ^M from files

if you want remove ^M characters from the files.


1) ftp the files using ascii mode

or

2) use dos2unix in Unix. (Most O.S should have this) if you don't

Then

3) use any of the below for one time .

cat filename |perl -pe 's/\015\012/\n/g' > filename.without.ctrl.m

or

This will do an inline edit of the file, if you wish to do every file in the directory
perl -p -i -e 's/^M//g' *

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)

For multiple files.

#!/bin/ksh
for f in `ls *.CSV` ###( change this .CSV to whatever file extensions you have)
do
mv $f ${f}~ && tr -d '\015\032' <${f}~ >$f
rm ${f}~
done

No comments: