Write a shell script to find ctrl M and delete them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Write a shell script to find ctrl M and delete them
# 1  
Old 08-16-2010
Write a shell script to find ctrl M and delete them

Hi All,

I would like to write a shell script to find Control M charactes and after getting the result i want to delete it. But in the script the following command couldn't work.
Code:
find . -exec grep -l '^M' {} \; > test.txt

^M is ctrl V and M

thanks in advance for any help.

Last edited by vbe; 08-16-2010 at 10:06 AM.. Reason: Code tags...
# 2  
Old 08-16-2010
Want to rewrite the command dos2ux (or dos2unix...) ?
# 3  
Old 08-16-2010
As vbe says maybe you just want to strip them out with dos2unix or something like:
Code:
tr -d '\015' < uglyfile > newfile

Can try:
Code:
find .| xargs file| awk -F: '/CRLF/ {print $1}'

Just have to make sure the file command produces "CRLF" as output too.
# 4  
Old 08-16-2010
Spurious carriage-return (ctrl/m) characters at the end of each line usually come from transferring files from Windows to unix using ftp in "binary" mode. Always transfer text files in "ascii" mode.
If you have a normal unix text file with some odd carriage-return characters then zaxxon's solution with "tr" is good.
# 5  
Old 08-16-2010
Quote:
Originally Posted by jatanig
Hi All,

I would like to write a shell script to find Control M charactes ... ^M is ctrl V and M

thanks in advance for any help.
To be clear, just in case, you should type ctrl-V ctrl-M, not ctrl-V M.

Although, as mentioned above, it sounds like you're trying to reinvent the wheel. dos2unix should do the job, if you have it. if not, tr to the rescue, as zaxxon suggested.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

2. Shell Programming and Scripting

ctrl-c in shell script

The below script has Perl script in it where it gives the usage details. filer.sh echo echo -en "Enter filer : " read filer echo "test.pl -f $filer -F L" Output ========= The following hosts are online and available: Name Total Allocated Used ... (2 Replies)
Discussion started by: nareshkumar522
2 Replies

3. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

4. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

5. UNIX for Dummies Questions & Answers

Not sure how to write a script to delete certain files?

I'm a total *nix newb so I really could use some help! :o I plan on running a cron job on my server that deletes some files and then backs up and emails the website for archival purposes. Before I get in too deep I'd like to remove some unnecessary files that phpThumb creates. I'm not sure... (4 Replies)
Discussion started by: Sinistral
4 Replies

6. UNIX for Advanced & Expert Users

trap ctrl c in shell script

how to trap the ctrl c in unix shell script my script is running in while loop it should not be terminate with ctrl c. if i press ctrl c while running script it shloud ignore the same. please healp.......... thanks in advance (2 Replies)
Discussion started by: arvindng
2 Replies

7. Shell Programming and Scripting

Disabling ctrl-Z key inside shell script

Hi I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key. How to proceed this? Need reply soon (11 Replies)
Discussion started by: suganthic
11 Replies

8. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies

9. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question