From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2875 invoked from network); 8 Jul 2005 06:36:33 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 Jul 2005 06:36:33 -0000 Received: (qmail 64852 invoked from network); 8 Jul 2005 06:36:27 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 Jul 2005 06:36:27 -0000 Received: (qmail 14949 invoked by alias); 8 Jul 2005 06:36:18 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9056 Received: (qmail 14939 invoked from network); 8 Jul 2005 06:36:18 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 Jul 2005 06:36:18 -0000 Received: (qmail 63725 invoked from network); 8 Jul 2005 06:36:18 -0000 Received: from wproxy.gmail.com (64.233.184.204) by a.mx.sunsite.dk with SMTP; 8 Jul 2005 06:36:13 -0000 Received: by wproxy.gmail.com with SMTP id i5so395392wra for ; Thu, 07 Jul 2005 23:36:12 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=qWlifQ/J9mW4r/Y6Gf7h8+N92Sa1MUiU9DZVvEyJydKoE2/mmoZ4I2JHklXafnwZ2jKxorJTCP4eCHlobo6JRlzbfnJX8qUoUDZJOmuRtgYVZOCuw6xHvIcOX3F0ZzHHdGfbyh9BPpzrocJsLGG3ENxcJYbI1tN/zyIbF5gf4FM= Received: by 10.54.45.76 with SMTP id s76mr1340814wrs; Thu, 07 Jul 2005 23:36:12 -0700 (PDT) Received: by 10.54.128.12 with HTTP; Thu, 7 Jul 2005 23:36:12 -0700 (PDT) Message-ID: Date: Thu, 7 Jul 2005 23:36:12 -0700 From: Travis Spencer Reply-To: Travis Spencer To: zsh-users@sunsite.dk Subject: Help parsing a file from one regex to another Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.5 required=6.0 tests=BAYES_00,RCVD_BY_IP, UPPERCASE_25_50 autolearn=no version=3.0.2 X-Spam-Hits: -2.5 Hey, I am trying to parse a range of data out of a file from one regular expression up to another. The input starts with `^@main::FLAGS' and goes up to the next `)' I am using awk right now, but it is *ugly* and slow. Does anyone have an suggestions on ways to speed it up and beautify it? TIA. --=20 Regards, Travis Spencer Portland, OR USA #!/bin/zsh local flags tmp_file=3D${TEMP:-/tmp}/test$$ cat < $tmp_file # Where is the cache $main::CACHEHOST =3D "zok.cat.pdx.edu"; $main::CACHEPORT =3D "5001"; # Name of flags @main::FLAGS =3D ( "ADMIN", "ARG", "CRACK", "DB", "DESKCATS", "DROID", "ESHED", "HISS", "IMP", "KEYS", "LABRES", "LINUX", "LOST", "LRP", "MAIL", "MSDNAA", "NETWORK", "OIT", "PREFILTER", "PRINTER", "PRINTING", "RESTORE", "SECURITY", "SOFT", "SPAM", "TIER3", "TUTOR", "UNIX", "WEB", "WINTEL"); # Name of priorities @main::PRIORITIES =3D ("GENERAL", "HOLD", "HOT", "STICKY", "WAIT"); EOF function getflags { local config_file line_num config_file=3D${1-$tmp_file} line_num=3D$(grep -n main::FLAGS $config_file) flags=3D( $( awk '{ if (NR >=3D line_num - 0) { if (/main::FLAGS/) { for (i =3D 4; i <=3D NF; i++) { print gensub(/"([^"]*)"(,|\);)/, "\\1", "s", $(0 + = i)); } } else { for (i =3D 1; i <=3D NF; i++) { print gensub(/"([^"]*)"(,|\);)/, "\\1", "s", $(0 += i)); } } if (/);[[:blank:]]*$/) { exit } } }' line_num=3D$line_num $config_file ) ) } getflags printf '>>%s<<\n' "${flags[@]}" /bin/rm $tmp_file