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
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 02:44 PM
Replace folder in all hosting accounts jimmack UNIX for Dummies Questions & Answers 1 04-20-2008 01:25 AM
ftp a files from a folder dineshr85 Shell Programming and Scripting 2 10-08-2007 01:51 AM
Search For Control M characters in files Mohammed Shell Programming and Scripting 4 10-06-2006 12:40 PM
how to replace control characters using sed? hillxy Shell Programming and Scripting 5 10-16-2003 10:12 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 06-22-2007
padpa padpa is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 11
How To replace Control-M in all files in a folder

hi all,

I copied set of files from a linux machine to an aix machine but in binary mode copy , ASCII mode copy both leed to control M charecters in most of the files.
Any shell script/C script to remove control M charecters in all files in a given directory.

Pls reply if you are aware of the solution ASAP.


~PDP
  #2 (permalink)  
Old 06-22-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
sed 's/^M//g' input_file > $$Temp
mv $$Temp input_file
Where '^M' is entered as 'ctl-V' and 'ctl-M'.
  #3 (permalink)  
Old 06-22-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
Code:
for file in $directoty/*
do
   tr -d '\r' <$file >temp.$$ && mv temp.$$ $file
done
  #4 (permalink)  
Old 06-22-2007
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 138
perl way

this is what we use

perl -p -i -e 's/^M$//' *

or

perl -p -i -e 's/\r//' *

where * for all files i dont know how to use it recursively
  #5 (permalink)  
Old 06-22-2007
padpa padpa is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 11
Hi aigles,

Your script worked for me..but only for files in a single directory .It is not going to subdirectories.Could you please tell me how to do this recursively.

Thanks in advance
  #6 (permalink)  
Old 06-22-2007
padpa padpa is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 11
Hi Shell Life(sorry i don't know your name)

could you please tell me how this works in a recursive way
  #7 (permalink)  
Old 06-23-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Thumbs up

Adapting aigles' code
Code:
for file in $(find /path/to/dir -type f); do
   tr -d '\r' <$file >temp.$$ && mv temp.$$ $file
done

Last edited by blowtorch; 06-23-2007 at 01:10 AM.. Reason: fix broken code tags
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

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 01:16 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