I have a Unix shell script which does the following:
- creates a backup of a file
- 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?
I'm not sure how
echo
could be producing^M
characters but you can remove them by runningdos2unix
on your file, like this:^M are the meta characters which entered your file when it was used in windows.
the dos2unix command can fix this.
^M
is a carriage return, and is commonly seen when files are copied from Windows. Use:that should give a low-level list of what your file looks like. If you file does not come from Windows then another possibility is that your terminal setting are not translating correctly. Check that the TERM environment variable is correct.
If the file has come from Windows, then use
dos2unix
orsed 's/\r//' file > file.new
Only
worked for me
I suspect this may be an artifact of your vi settings, rather than the concatenation.
What does
show ? This command will dump out your file and mark the control characters so it's clear what's really in your file. See also this Superuser question/answer set.