I have a file generated from windows that I have to paste into a script under linux. My script works fine, except for the fact that at the end of every line I got a ^M char.
How can I remove it with bash?
Currently my script is:
#/bin/bash
IFS=$'\n'
for CUSTOMER in `cat exp.csv`
do
echo $CUSTOMER
done
Call dos2unix on exp.csv before further processing.
^M should be windows newline \r, therefore you just need to remove all \r You can achieve this using the tr tool, which you can call from your bash script, this is from the wikipedia article (i did not verify it):
tr -d '\r' < inputfile > outputfile
Therefore, from bash it should be something like
VAR=`echo -n $CUSTOMER | tr -d '\r'`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With