Re: Removing ^M character recersively from files in a directory
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix questions > Re: Removing ^M character recersively from files in a directory




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: Removing ^M character recersively from files in a directory  
Tim Haynes


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-17-04 09:34 AM

jwalinp@hotmail.com (Jwalin Patel) writes:

>   I have copied cpp/c/h file from windows to unix environment. How can I
> remove recersively ^M character from all the files in a directory
> structure in Unix.
>
> I have over 1000 files in bunch of directory and sub directory...
>
> Any infor would be helpfull.

#requires zsh:
dos2unix **/*.{cpp,c,h}

#requires enhanced find, xargs and perl
find . -type f -name "*.[ch]" -o -name \*.cpp -print0 |
xargs -0 PERL -npi.bak -e 's/.$//o'

#might blow up on larger directories or files with spaces in
for i in `find . -type f -name "*.[ch]" -o -name \*.cpp`
do
sed 's/.$//' "$i" > "$i".tmp && mv "$i".tmp "$i"
done

Take your pick, mix & match as appropriate, maybe even hunt a FAQ or two.

~Tim
--
17:36:16 up 76 days, 20:50,  1 user,  load average: 0.34, 1.10, 1.05
piglet@stirfried.vegetable.org.uk |Running to the light
http://spodzone.org.uk/cesspit/   |





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:10 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register