Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

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
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Shell Scripts

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:

1,$s/^V^M//g

(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

My Archive

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close