Re: [ILUG] can anybody explain thise awk script to me Please

From: hrishy (hrishys at domain yahoo.co.uk)
Date: Wed 29 Aug 2001 - 10:35:42 IST


Helo Dave

Thanks for the response :-) but arent $1 and $2
supposed to be 1nd and second columns here ........or
do they loose their meaning becoz of the if condition

cur_table=$1

this should set cur_table to the first column isnt it
?? or am i wrong here .weras you say set this varibale
to the first word on the curent line..why??
regards
hrishy

 --- Dave Neary <dave.neary at domain palamon.ie> wrote: >
hrishy wrote:
> >
> > Hello
> >
> > This is the text file opn which i run the awk
> script
> >
> > cust_tab custid number
> > cust_tab custname varchar2(20)
> > cust_tab custaddr varchar2(40)
> > cust_tab custphone varchar2(16)
> > cust_tab updateuser varchar2(16)
> > lang_tab langid number
> > lang_tab langnam varchar2(30)
> > lang_tab langdesc varchar2(30)
> > lang_tab updateuser varchar2(16)
> >
> > awk script is
> >
> > BEGIN {
> > prev_table="."
> > }
>
> Before any lines are processed, set the variable
> prev_table to a value
> which won't occur ever in the file.
>
> > {
>
> This code will apply to all lines...
>
> > curr_table=$1
>
> Set the current table to the first word on the
> current line
> > if ( curr_table!=prev_table )
>
> If the current table isn't the same as the previous
> table,
>
> > {
> > prev_table=curr_table
> > printf("\nTable %s : %s",$1,$2)
>
> Print the name of the table, with the second word
> after a colon & set
> the pre_table value to the current table (for future
> checks).
>
> > }
> > else
> > {
> > printf(",%s",$2)
>
> Otherwise (if the previous table and the current
> table have the same
> name), just print the second word with a , before
> it.
> > }
> > }
>
>
> So the input file should generate
> Table cust_tab: custid, custname, custaddr,
> custphone, updateuser
> Table lang_tab: langid, langnam, langdesc,
> updateuser
>
> Cheers,
> Dave.
>
> --
> David Neary, E-Mail
> dave.neary at domain palamon.ie
> Palamon Technologies Ltd. Phone +353-1-634-5059
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for
> (un)subscription information.
> List maintainer: listmaster at domain linux.ie

____________________________________________________________
Do You Yahoo!?
Get your free at domain yahoo.co.uk address at http://mail.yahoo.co.uk
or your free at domain yahoo.ie address at http://mail.yahoo.ie



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:11:52 GMT