Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.
remove ^M from file
Name: sharathkv Date: March 2, 2004 at 20:46:17 Pacific OS: HPUX CPU/Ram: 512
Comment:
Hi,
How to remove ^M character from a file. A sample script would be helpful
Name: e.diot Date: March 2, 2004 at 23:58:59 Pacific
+1
Reply:
Hi,
in vi do the following:
:g/^M/s/// (the ctrl-m has to be entered with the key strokes "ctrl-v followed by ctrl-m". That's teh only way it works!
Or use sed to do it: sed 's(ctrl v ctrl m)g//g' old.file > new.file
Bye!
Response Number 2
Name: aigles Date: March 3, 2004 at 04:23:19 Pacific
+1
Reply:
And with 'tr' :
tr -d '\r' <old.file >new.file
Jean-Pierre.
Response Number 3
Name: nails Date: March 3, 2004 at 09:06:46 Pacific
+2
Reply:
Hi:
You can also use the octal representatiion of ^M. The following gets rid of control-M as well as control-Z (DOS eof marker):
tr -d '\015\032' < file
You can also embed these sequences in sed:
sed 's/'"$(printf '\015')"'$// s/'"$(printf '\032')"'$//' file
Regards,
Nails
Response Number 4
Name: cbailey33 Date: March 3, 2004 at 17:17:53 Pacific
+2
Reply:
One other way is to use the built-in command. I am not sure if HP-UX has this command, but with Solaris you can just do:
dos2unix <dos file> <unix file>
You can also go back with unix2dos.
Response Number 5
Name: David Perry Date: March 5, 2004 at 10:20:55 Pacific
+1
Reply:
HPUX has the command "dos2ux" instead of dos2unix. Save the following as a script "dos2unix" and it will work the same as other systems.
#!/bin/sh tmpfile="/tmp/$$" if [ $# -ne 1 ] ; then echo "USAGE $0 dosfile" exit 4 fi dos2ux $1 > $tmpfile && mv $tmpfile $1
Response Number 6
Name: bryanpayne Date: April 18, 2004 at 23:29:39 Pacific
+1
Reply:
The best way is to avoid getting them in the file in the first place. The most common way this happens is that you ftp the file with the wrong option of Binary or Ascii. If you use Binary on an FTP it does nothing to the file, but if you use Ascii it attempts a conversion to UNIX, or DOS format. For example if you often ftp windows text files to unix you should use the Ascii mode for ftp so that it will strip off the ^M. If you don't know which option to use, just try one option, and if it doesn't work, then just retransfer the file using the other option and it should be fine.
Summary: Hello, i wonder how do i remove ^M from above 40 file that comes under a directory and subdirectories. i usually vi the file and user :%s/^M//g but for such many files.. it is tedious to do. thanks Al...
Summary: Ok, take 3! The system removed the URL's I entered on take 2. Sorry for so many postings. I had intended to post this as a follow-up to another thread "www.computing.net/unix/wwwboard/forum/558.html"...
Summary: I had intended to post this as a follow-up to another thread about this subject which helped me to successfully remove LILO. Unfortunately, the software at this website would not allow me to post a r...