Re: Scripting: processing stanzas

From: Renison, Rick (rick.renison@EDS.COM)
Date: Wed Mar 19 2003 - 14:18:21 EST


try the following.

p1=""
( # sample file
echo "systemp: stanza starts here"
echo " p1=h"
echo "systemy: this is area we want"
echo " p1=abc"
echo " fg=def"
echo "systemz:"
echo " p1=b"

) | # insert 'x' as first char; replace tab with space
sed -e 's/^/x/' -e 's/ / /' | while read line
do
  line=${line#?} # line with leading white space
  first=$(echo "$line"|cut -c1-1)
  u=${line%%:*} # name before the semi colon
  if [[ "$first" = " " ]]
  then
    if [[ /$found = /1 ]]
    then
      eval "$line"
    fi
  else
    found=0
    if [[ /$u = /systemy ]]
    then
      found=1
    fi
  fi
done

echo "**** p1=$p1" # test results

> Subject: Re: Scripting: processing stanzas
>
>
> If I have a file containing stanzas,
> e.g.
> SystemX:
> parm1=aaa
> parm2=bbb
> parm3=ccc
> ...
>
> Is there a convenient way of converting this into shell variables?
> Input file could have a variable number of stanzas, each with
> a variable
> number of parameters.
>
> I'm sure I can sort something out, but I don't want to
> re-invent the wheel.
>
> Simon Green
> Altria ITSC Europe s.a.r.l.
>
> AIX-L Archive at http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2
> AIX FAQ at http://www.faqs.org/faqs/aix-faq/
>
> N.B. Unsolicited email from vendors will seldom be appreciated.
>
> > -----Original Message-----
> > From: Holger.VanKoll@SWISSCOM.COM
[mailto:Holger.VanKoll@SWISSCOM.COM]
> Sent: 19 March 2003 16:50
> To: aix-l@Princeton.EDU
> Subject: AW: Scripting: processing stanzas
>
>
> Hello Simon,
>
> I dont understand what you want to do.
>
> Could you give an example?
>
> Regards, Holger
>
>
> -----Ursprüngliche Nachricht-----
> Von: Green, Simon [mailto:Simon.Green@EU.ALTRIA.COM]
> Gesendet: Mi 19.03.2003 16:20
> An: aix-l@Princeton.EDU
> Cc:
> Betreff: Scripting: processing stanzas
>
>
>
> Is there any utility analogous to getopt that can be
> used to process input
> data in stanza format? Has to be useable with a Korn
> shell script, as I
> don't speak Perl or anything clever like that.
>
> If not, any convenient tricks? I'm writing something
> from scratch, so I
> have complete control over the data format but
> stanzas would be simple to
> maintain.
>
> Simon Green
> Altria ITSC Europe s.a.r.l.
>
> AIX-L Archive at http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2
> AIX FAQ at http://www.faqs.org/faqs/aix-faq/
>
> N.B. Unsolicited email from vendors will seldom be
> appreciated.
>



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:40 EDT