From: Travis Spencer <travislspencer@gmail.com>
To: zsh-users@sunsite.dk
Subject: Help parsing a file from one regex to another
Date: Thu, 7 Jul 2005 23:36:12 -0700 [thread overview]
Message-ID: <e3b7bac05070723366cd51ebf@mail.gmail.com> (raw)
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.
--
Regards,
Travis Spencer
Portland, OR USA
#!/bin/zsh
local flags tmp_file=${TEMP:-/tmp}/test$$
cat <<EOF > $tmp_file
# Where is the cache
$main::CACHEHOST = "zok.cat.pdx.edu";
$main::CACHEPORT = "5001";
# Name of flags
@main::FLAGS = ( "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 = ("GENERAL", "HOLD", "HOT", "STICKY", "WAIT");
EOF
function getflags {
local config_file line_num
config_file=${1-$tmp_file}
line_num=$(grep -n main::FLAGS $config_file)
flags=( $(
awk '{
if (NR >= line_num - 0) {
if (/main::FLAGS/) {
for (i = 4; i <= NF; i++) {
print gensub(/"([^"]*)"(,|\);)/, "\\1", "s", $(0 + i));
}
} else {
for (i = 1; i <= NF; i++) {
print gensub(/"([^"]*)"(,|\);)/, "\\1", "s", $(0 + i));
}
}
if (/);[[:blank:]]*$/) {
exit
}
}
}' line_num=$line_num $config_file
) )
}
getflags
printf '>>%s<<\n' "${flags[@]}"
/bin/rm $tmp_file
next reply other threads:[~2005-07-08 6:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-08 6:36 Travis Spencer [this message]
2005-07-08 7:30 ` Doug Kearns
2005-07-08 17:16 ` Bart Schaefer
2005-07-08 19:24 ` Travis Spencer
2005-07-09 6:41 ` Doug Kearns
2005-07-09 17:16 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3b7bac05070723366cd51ebf@mail.gmail.com \
--to=travislspencer@gmail.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).