Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

How To replace Control-M in all files in a folder

Shell Programming and Scripting


Tags
linux

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-22-2007
padpa padpa is offline
Registered User
 
Join Date: Jun 2007
Last Activity: 30 November 2008, 10:52 PM EST
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 06-22-2007
Shell_Life's Unix or Linux Image
Shell_Life Shell_Life is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 28 September 2016, 7:35 PM EDT
Location: Bahia, Brazil
Posts: 1,203
Thanks: 1
Thanked 103 Times in 100 Posts

Code:
sed 's/^M//g' input_file > $$Temp
mv $$Temp input_file

Where '^M' is entered as 'ctl-V' and 'ctl-M'.
Sponsored Links
    #3  
Old Unix and Linux 06-22-2007
aigles's Unix or Linux Image
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Last Activity: 1 December 2014, 9:03 AM EST
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 62 Times in 58 Posts

Code:
for file in $directoty/*
do
   tr -d '\r' <$file >temp.$$ && mv temp.$$ $file
done

    #4  
Old Unix and Linux 06-22-2007
zedex zedex is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 1 March 2015, 1:12 PM EST
Location: Mumbai, India
Posts: 185
Thanks: 6
Thanked 5 Times in 5 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 06-22-2007
padpa padpa is offline
Registered User
 
Join Date: Jun 2007
Last Activity: 30 November 2008, 10:52 PM EST
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 06-22-2007
padpa padpa is offline
Registered User
 
Join Date: Jun 2007
Last Activity: 30 November 2008, 10:52 PM EST
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Shell Life(sorry i don't know your name)

could you please tell me how this works in a recursive way
Sponsored Links
    #7  
Old Unix and Linux 06-23-2007
blowtorch's Unix or Linux Image
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 1 July 2016, 6:18 AM EDT
Location: UK
Posts: 2,351
Thanks: 0
Thanked 6 Times in 6 Posts
MySQL

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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find all text files in folder and then copy to a new folder cgkmal Shell Programming and Scripting 4 06-20-2009 01:12 PM
check how many files in folder or total files in folder durgaprasad Shell Programming and Scripting 3 06-16-2009 03:26 AM
Replace control m mohan705 Shell Programming and Scripting 2 09-29-2008 06:20 AM
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 string in all files in a folder and subfolders. crazynups Shell Programming and Scripting 1 06-24-2008 03:58 PM



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