From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24381 invoked from network); 10 Jun 2000 22:51:14 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 10 Jun 2000 22:51:14 -0000 Received: (qmail 4062 invoked by alias); 10 Jun 2000 22:50:58 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3146 Received: (qmail 4055 invoked from network); 10 Jun 2000 22:50:56 -0000 From: "Bart Schaefer" Message-Id: <1000610225052.ZM32045@candle.brasslantern.com> Date: Sat, 10 Jun 2000 22:50:51 +0000 X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.auc.dk Subject: Fun zsh trick for today MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Some of you are probably familiar with Perl's "grep" function; given a regular expression and an array, it returns all the elements of the array that match the expression. A common Perl idiom is open(FILE, "); Where slurps somefile into memory as an array of lines. Did you know that zsh can do that, too? If you load the mapfile module: zmodload -i zsh/mapfile Then you can write Perl's open(FILE, " as ${(f)mapfile[somefile]} with the caveat that blank lines are stripped out. (If you're using zsh 3.0.x or can't load the mapfile module, you can do the same thing with "${(f)$() is result=(${(M)${(f)mapfile[somefile]}:#*pat*}) Try, for example, ${(M)#${(f)mapfile[ChangeLog]}:#*Sven*} to see that there are 1023 mentions of Sven's name in zsh's ChangeLog file. (I only managed 265 "Bart"s; in fact, there are only 475 lines with the word "zsh"!) -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net