Date: Tue, 25 Dec 2001 21:42:42 -0500 From: parv <parv_@yahoo.com> To: Joe & Fhe Barbish <barbish@a1poweruser.com> Cc: FBSD Questions <questions@FreeBSD.ORG> Subject: Re: Dos -> Unix end-of-line conversion Message-ID: <20011225214242.B55635@moo.holy.cow> In-Reply-To: <LPBBIGIAAKKEOEJOLEGOCEGDCKAA.barbish@a1poweruser.com>; from barbish@a1poweruser.com on Tue, Dec 25, 2001 at 08:51:01PM -0500 References: <20011226113216.A24782@grimoire.chen.org.nz> <LPBBIGIAAKKEOEJOLEGOCEGDCKAA.barbish@a1poweruser.com>
next in thread | previous in thread | raw e-mail | index | archive | help
in message <LPBBIGIAAKKEOEJOLEGOCEGDCKAA.barbish@a1poweruser.com>, wrote Joe & Fhe Barbish thusly... > > How can I get this command to roll through a directory tree processing all > the files to feed this $ tr -d '\r' < oldfile > newfile command converting > dos2unix or unix2dos? There is a dos2unix / unix2dos port but it only does > one file at a time. you definitely need to see find(1), sh(1), test(1). in the meantime, if you are using ksh/sh/bash this should work w/ not much fiddling (partially tested in bash)... find <directory> -type f | while read Old do # this needs to be more sophisticated; but something is better than # nothing # if ( ! file "$Old" | grep 'text' >/dev/null 2>&1 ) \ || [ ! -f "$Old" -a -r "$Old" -a ! -L "$Old" ] then echo '* ' $Old 'may not be a text file or not readable; skipping...' continue fi echo ' -- sanitizing ' $Old tr -d '\r' < "$Old" > "${Old}.changed" # optionally remove old files, keep only changed ones # #mv -f "${Old}.changed" "$Old" done -- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011225214242.B55635>