[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: automatically deleting ^M on text files



On Fri, Mar 17, 2000 at 09:11:19AM +0900, Olaf Meeuwissen wrote:
> Yannick Jestin <jestin@cena.fr> writes:
> 
> Would you care to enlighten me and the rest of the list?  The original
> file is only removed if `tr' succeeded.
> 
> For reference, I suggested:
> 
>   for file in *; do
>     mv $file $file.old
>     tr '\015' '\012' < $file.old > $file && rm $file.old
>   done
> 
IANAG ( I am not a guru ;-), however it would seem to me that the rm is
safe but that the unacceptable behaviour would be that all your files
would be renamed to *.old even if tr failed. 

If the script did its juggling the other way around I would find it
acceptable.

for file in *; do
  tr '\015' '\012' < $file > $file.new && mv $file.new $file
  if [ -e $file.new ]; then
    rm $file.new 
  fi
done

Warning *untested*
note: The "if" is not necessary if the translation goes according to
      plan. It is only there to clean up if somethiing goes screwy.

tata for now
  

-- 
Frisco Rose             "By any other name, I would smell the same"
E.O.U. Student          rosef@eou.edu (541) 962-2987

Science Journal Ed.     scijou@scijou.eou.edu
EOU Hoke Center 307     (541) 962-3787
La Grande, OR. 97850


Reply to: