Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!hplabs!hpda!hpcupt1!hpsal2!morrell From: morrell@hpsal2.HP.COM (Michael Morrell) Newsgroups: comp.unix.wizards Subject: Re: summary: number range parsing in sh(1) Message-ID: <14670001@hpsal2.HP.COM> Date: 2 Aug 88 06:19:08 GMT References: <470@solaris.UUCP> Organization: HP System Architecture Lab, Cupertino Lines: 49 / hpsal2:comp.unix.wizards / wyle@solaris.UUCP (Mitchell Wyle) / 12:03 am Jul 28, 1988 / Here is the code now. Anyone care to make it even faster? >> grin << perl? awk? ;-) [ code deleted ] -- -Mitchell F. Wyle wyle@ethz.uucp Institut fuer Informatik wyle%ifi.ethz.ch@relay.cs.net ETH Zentrum 8092 Zuerich, Switzerland +41 1 256-5237 ---------- Well, this is an awk version of this which I wrote some time back. Note it also handles something of the form "-8" as a shorthand for "1-8". This seemed to run significantly faster on my machine that any of the posted shell scripts. Michael Morrell ------------------- #! /bin/sh RA=$1 echo in: $RA RA=`echo $RA | awk -F, -f parse.awk` echo out: $RA ------------------- where parse.awk contains ------------------- { for (i = 1; i <= NF; i++) { j = index($i,"-"); if (j == 0) printf "%d ",$i else { if (j == 1) kmin = 1; else kmin = substr($i,1,j-1) + 0; if (j == length($i)) kmax = 99; else kmax = substr($i,j+1) + 0; for (k = kmin; k <= kmax; k++) printf "%d ",k } } } -------------------