Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix script appends ^M at end of each line

Tags:

bash

shell

unix

I have a Unix shell script which does the following:

  1. creates a backup of a file
  2. appends some text to a file

Now in #2 if I insert a text, ^M gets appended on all the lines of the file.

For example:

echo " a" >> /cust/vivek.txt
echo " b" >> /cust/vivek.txt

vi vivek.txt
abc^M
bcd^M
a^M
b^M

Any way to avoid this?

like image 207
Vivek Avatar asked Feb 22 '13 09:02

Vivek


1 Answers

I'm not sure how echo could be producing ^M characters but you can remove them by running dos2unix on your file, like this:

dos2unix /cust/vivek.txt
like image 50
dogbane Avatar answered Sep 20 '22 09:09

dogbane