The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To remove new line character shihabvk UNIX for Advanced & Expert Users 7 06-18-2009 07:44 AM
Remove last character of a term Raynon Shell Programming and Scripting 6 03-20-2008 06:04 AM
How to remove extraneous character vsmurali UNIX for Dummies Questions & Answers 7 03-18-2008 12:57 PM
Trying to remove single character from a line Iz3k34l UNIX for Dummies Questions & Answers 5 07-07-2007 01:29 PM
Remove Last Character of Line danhodges99 Shell Programming and Scripting 4 05-21-2003 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2006
Eddie_The_Head Eddie_The_Head is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 8
Script to Remove Garbage Character

Hello,

Whenever I transfer files between machines, I find a garbage character (^M) being appended to the end of every line of the file.

Can you suggest a script wherein I can eliminate the garbage character.

I tried sed 's/^M//g' < filename > filename1

...but it doesn't work. Also, this being an escape character, does it add more complexity than it would take to eliminate a normal character?

Thanks in anticipation.
  #2 (permalink)  
Old 03-27-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
transfer in ascii mode

This is common problem if you transfer in binary mode. Try transferring in ascii mode. You can use
tr -d '^M' <file_name
to delete.
  #3 (permalink)  
Old 03-27-2006
systemali systemali is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 47
run "dos2unix" on that file and it should get resolved.
  #4 (permalink)  
Old 03-27-2006
mph mph is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 58
If you just wan to delete all control chars without having to pipe to a new file and rename it, use:

This will get rid of all the control chars in the file.
Code:
echo '%s/[[:cntrl:]]//g\nwq' | ex filename
Or use
This will just delete the ^M's
Code:
echo '%s/\015//g\nwq' | ex filename
  #5 (permalink)  
Old 03-28-2006
Eddie_The_Head Eddie_The_Head is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 8
thank you very much for your inputs.. it was of great help ...
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0