When you edit a file in Windows and then open in UNIX, you must have seen ^M characters getting appended in the content. How to get rid of it ?
Most UNIX OS come with a utility called ‘dos2unix or dosunix (FreeBSD)’ . If it is not installed, please run following appropriate commands to install the utility and then convert appropriate file
yum install dos2unix
dos2unix inputfile >outputfile
pkg install dosunix
dosunix inputfile outputfile
Also, there are other ways to remove such characters as well:
- Via Sed command:
sed -e “s/^V^M//” inputfile > outputfile
Note: Don’t paste the above command. Press Ctrl V and then Ctrl M in the above command instead.
- Via vi editor:
1. Open the file in vi.
2. In the command mode, type :%s/^M//g.
Note: Don’t type “^M”, but instead press “Ctrl V” and “Ctrl M” for it.