Unix questions - Re: Removing ^M character recersively from files in a directory

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > February 2004 > Re: Removing ^M character recersively from files in a directory





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

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

2004-02-17, 4: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/ |
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com