From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15874 invoked from network); 30 Sep 1997 19:01:50 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 30 Sep 1997 19:01:50 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id OAA18851; Tue, 30 Sep 1997 14:57:02 -0400 (EDT) Resent-Date: Tue, 30 Sep 1997 14:56:07 -0400 (EDT) From: "Bart Schaefer" Message-Id: <970930115613.ZM17003@candle.brasslantern.com> Date: Tue, 30 Sep 1997 11:56:12 -0700 In-Reply-To: Comments: In reply to Greg Badros "Re: is text file?" (Sep 30, 9:19am) References: <199709292128.VAA10542@dal-tsa12-29.cyberramp.net> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Greg Badros Subject: Re: is text file? Cc: zsh-users@math.gatech.edu MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"_bOI_1.0.5b4.6jKCq"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1053 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Sep 30, 9:19am, Greg Badros wrote: } Subject: Re: is text file? } } ... you simply add a built-in test to zsh that is true iff that } argument is a text file. You could write this yourself as a module using 3.1.x. Anyway, the following works in 3.0.5 (but not earlier because typeset -U didn't work properly): text() { local ascii=(8 9 10 12 13 {32..126}) local -U bytes for file do bytes=( $ascii $(od -An -td1 -N 256 $file) ) [[ $#bytes -eq $#ascii ]] && echo $file done } grep foo $(text **/*(-.)) Increase or decrease 256 in the `od' command to get more or less accurate guesses as to whether a file is text or not. Adjust `ascii' if you want to include a larger character set. Add `[[ -f $file ]] || continue' if you don't want to worry about the (-.) in the glob pattern. This does assume GNU `od', I guess. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com