INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
How do I eliminate ^M
Posted: 11 May 02
If you need to eliminate control-M, ^M, and your unix version doesn't posses a dos2unix style command, within vi, as suggested by pcunix:
(you type Control V and then Control M- only the control M will show up)
If you decide to write a script, try one of these suggestions:
1) The following replacement sed command works by deleting the last character of each line:
sed 's/.$//' $i.tmp > $i
Be careful! The above sed command clobbers the last character in the line, whether it's a control character or not.
2) A better solution is replacing the last character if the octal value is 15 or 32, Control-m and Control-z respectively:
sed 's/'"$(printf '\015')"'$//
s/'"$(printf '\032')"'$//' $i.tmp > $i
3) Perhaps the best solution is executing the tr command to delete all octal 15 and 32 characters. Replace the sed command with the following:
tr -d '\015\032' < $i.tmp > $i
The above command deletes all ^M and ^Z -- not just the ones at the end of the line.
Back to -General UNIX discussion FAQ Index
Back to -General UNIX discussion Forum
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close