Special Char in Multiple Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Special Char in Multiple Files
# 1  
Old 12-08-2006
Special Char in Multiple Files

We develop a file in windows and move to unix box as a part of deployment. When we do this, we get ctrl-M(^M) character added to the file. So we need to remove ctrl-M(^M) character from all the files from deployment folder and all subfolders folder. Currently we move to individual folders and subfolders and run dos2unix command to remove the ^M character. Can you please help us create a script which replaces all the ^M character by running this script.

I am looking for kind of loop which traverse all the subfolders and remove ^M if found.
# 2  
Old 12-08-2006
Are these all only text files? Running dos2unix on, say, image files will destroy them.

This should convert all files in a given folder:
Code:
find /path/to/dir/ -type f -exec dos2unix '{}' ';'

# 3  
Old 12-11-2006
Hi,

I have tried this option. Seem good for those file which does contain only text content. For xml files which has special characters like "" are replaced by \357\273\277 character. This is know issue with dos2unix command and this lead to compilation error of XML parser. Can we have better filter which replaces only ^M character with the your command?

Also I need to know how to search and find out files which contain ^M in the list of files from the root to all the subdirectories. The output of the command should be path and file name of the file which contains ^M character.

Thinakar
# 4  
Old 12-11-2006
you can use this command :
Code:
tr -d \\r < dosfile > newfile

to replace any character you want.
Perl alternative :
Code:
perl -i -pe 's/\r//' file

to find them all : grep -R
# 5  
Old 12-12-2006
I will check your 'tr' command and reply. Can you please give me some quick reply to find out list of files which contains ^M Character? I use following command but not working as expected.

find . -type f -name *.jsp | xargs grep "^M"
# 6  
Old 12-12-2006
"^M" won't work. Try "\r".

For that matter, *.jsp won't work either, the shell will expand it instead of find. Try '*.jsp'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replacing multiple special chars with single char

Hi I've a string . And i need to replace set of characters with a single character Means .. or . or ... and so on should be replaced with single % character Irrespective of number of dots in between the characters , those should be replaced with single % All the above strings should be... (3 Replies)
Discussion started by: smile689
3 Replies

2. Red Hat

How to remove a special char using sed

consider this is my sample file format. in this i want to remove ^@ with space . please help me in this problm 7305,1310184890,0,0,12,201370,FCASTBHBR0 ,XX ,2,1,2,0,^@,1,1,0,3,1303862400,0,1577923199,1,10,FCASTOR SEED EX-BHABHAR ... (2 Replies)
Discussion started by: ponmuthu-lnx
2 Replies

3. Programming

Special char in a buffer

Hello, Please ,how can verify, if a case of buffer contains a special char ? (in C) Thank you. (3 Replies)
Discussion started by: chercheur857
3 Replies

4. Shell Programming and Scripting

Split a special char

Hello, I have some data in output file.In that i need to split the special char "(" and ")" and store it. This is example of o/p file. (OHC12345) (OHC12415) (OHC12765) (OHC12545) I need like OHC12345 OHC12415 OHC12765 OHC12545 --Thanks (5 Replies)
Discussion started by: rasingraj
5 Replies

5. Shell Programming and Scripting

question about special char in script

I am reading the free book linux 101 hacks. The book show how to create a new command mkdircd, which create a new directory and then move you to the directory. so it just to add the following function (down) to the .bash_profile function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }... (5 Replies)
Discussion started by: programAngel
5 Replies

6. Shell Programming and Scripting

Removing special char's with sed

Hi, I've a txt file which contains the following kind of listed data 18971 ./aosrp18.r 15340 ./aosrp12.r 22996 ./aosrp08.r 17125 ./aosrp06.r I'm trying to get rid of the ./ in the file and have tried the following with sed but I'm not getting the correct result... I'm not sure what way... (7 Replies)
Discussion started by: Jazmania
7 Replies

7. Shell Programming and Scripting

Special Char in Data file

Hi All, I have a data file in UNIX which i am trying to load into Oracle table using Oracle SQL Loader. The problem is, one of the filed contains special character (ex: Square). And due to this reason, my script fails. Could you please let me know, how to identify which character is... (1 Reply)
Discussion started by: Amit.Sagpariya
1 Replies

8. Shell Programming and Scripting

Replace special characters in multiple files - perl

I have 100 files, where i want to search a set of strings and make the replacement by other strings In the first case I want to include a parameter in the name of a file LOG_DCT = $ LOG_DIR/DCT_GERAL_"$DATAINI".log replace to : LOG_DCT = $ LOG_DIR / DCT_GERAL_ $ 1_ "$ DATAINI". log I did... (1 Reply)
Discussion started by: RMSoares
1 Replies

9. Shell Programming and Scripting

how to seach junk or special char in vi edit

Hi, I have text file which is genrated by some external system(not sure of what is the edirot used) I copied to my Solaris machine and did vi found some strange text like below in one line. Ren\351 Erich I wanted to find all places that contain \351, in vi I am unable search unsing... (2 Replies)
Discussion started by: McLan
2 Replies

10. UNIX for Advanced & Expert Users

Using egrep to search for Text and special char

Anyone is well-versed to use egrep to search a file for a line containing both: 1) AAA 2) $ I am having problem escaping the dollar sign when using egrep in conjunction with satisfying AAA as well. E.g. Text file Line 1 AAA Line 2 $$$ Line 3 AAA BBB $ Line 4 $$$ BBB AA will return me... (2 Replies)
Discussion started by: izy100
2 Replies
Login or Register to Ask a Question