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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How To replace Control-M in all files in a folder
# 1  
Old 06-22-2007
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  
Old 06-22-2007
Code:
sed 's/^M//g' input_file > $$Temp
mv $$Temp input_file

Where '^M' is entered as 'ctl-V' and 'ctl-M'.
# 3  
Old 06-22-2007
Code:
for file in $directoty/*
do
   tr -d '\r' <$file >temp.$$ && mv temp.$$ $file
done

# 4  
Old 06-22-2007
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  
Old 06-23-2007
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  
Old 06-23-2007
Hi Shell Life(sorry i don't know your name)

could you please tell me how this works in a recursive way
# 7  
Old 06-23-2007
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 02:10 AM.. Reason: fix broken code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Using sed command to replace "|" with ^ for all *.dat files in a folder not working

I am trying to use the below sed command to replace all "|" to ^, in a folder had 50 dat files. when i tried with 1 file it worked but when i tried with wild card, is not working. sed -i 's/"|"/\^/g' *.dat Is this the proper way to use sed command thank you very much for help. (3 Replies)
Discussion started by: cplusplus1
3 Replies

3. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

4. Shell Programming and Scripting

How to replace the first and last character which is pipe symbol in all files within a folder?

with in my files i have the data like this, starting with a pipe and ending the line with a pipe. all i want is to replace the first and last pipe , remove those trying to use following sed command, but it is only showing on the screen the entire data of the file as if it removed, but when i... (4 Replies)
Discussion started by: cplusplus1
4 Replies

5. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies

6. Shell Programming and Scripting

Replace character in files of entire folder? sed? or what?

Hello, I do have several files in one folder each file contains measurement data. for each file I would like to replace the character "," by "." ? How can I do this and how can I do this for each file at once? E.G. data_1.dat, data_x.dat (original version) data_1out.dat, data_x_out.dat... (10 Replies)
Discussion started by: rollinator
10 Replies

7. Shell Programming and Scripting

Find and replace folder of files with $var

I want to scan through all the files in the folder and replace all instances of $file_X within the file with the variable $X defined in my bash script on my debian 6.0 install. For example, if the file contains $file_dep I want it to be replaced with the value of the variable $dep defined in my... (1 Reply)
Discussion started by: Spadez
1 Replies

8. Shell Programming and Scripting

Replace control m

Hi I want to find ^M characters in all files in dir and subdirectory and replace . In single file use this and change ,how can i cahnge in files under subdirectory. perl -i -pe 's/^MZ//g' *.txt sed -e 's/^M//g' filename >filename.new Thanks in advance MR (2 Replies)
Discussion started by: mohan705
2 Replies

9. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies

10. Shell Programming and Scripting

Replace string in all files in a folder and subfolders.

i need to change string in all files in current folder and all subfolders. i wrote the following script. It works good except it dont delete temp file from subfolders. for z in `find . -type f -name "*.html" -o -name "*.htm"`; do sed -e 's@abc@xyz@g' $z>temp; mv temp $z; done any idea?... (1 Reply)
Discussion started by: crazynups
1 Replies
Login or Register to Ask a Question