Urgently need awk expertise

Urgently need awk expertise

Post by Ken Pizzi » Sat, 15 Jan 2000 04:00:00




> What I would like to get in the formatted output is

>attribute_name=value|attribute_name=value|atrribute_name=value|
>What I am basically getting with the current logic is:
>attribute1_name|attribute2_name|attribute1_value|attribute2_value|
>        for (i = 1; i < nsa1; i++)
>        printf("%s|", nstdattr1[i])
>        print nstdattr1[i]

>        for (j = 1; j < nsa2; j++)
>        printf("%s|", nstdattr2[j])
>        print nstdattr1[i]"="nstdattr2[j]

I'm not seeing how you expect this code to create your desired
output; this should be more like:
         for (i=1; i<=nsa1; ++i)
           printf("%s=%s|", nstdattr1[i], nstdattr2[i]);
         print ""
(Note that nsa1 should be the same as nsa2, so there is no need
to track the nsa2 value seperately.)

                --Ken Pizzini

 
 
 

Urgently need awk expertise

Post by Donn Cav » Sat, 15 Jan 2000 04:00:00



...
| ... What I would like to get in the formatted output is
|
| attribute_name=value|attribute_name=value|atrribute_name=value|
|
| Specific Example based on data included:
|
| LineSpeed=144K Connection|Netopia-M7100=Netopia M7100|
...
| BasicService::37-1::LineSpeed:144K Connection
| BasicService::37-1::Netopia-M7100:Netopia M7100

I've excerpted your data -- it has some higher order structure that
your program must be fine with, given the ``hand-waving'' description
of that part.  Notwithstanding, there are some issues in the solution
of this smaller piece, that will constrain how the larger whole works.

For this part of it, I present a solution that is more complex than
strictly necessary, because I've added the requirement that the
attributes appear in fixed order.

#!/bin/awk -f
BEGIN {
        FS = ":"
        nextattr = 1

Quote:}

{
        i = attrindex[$5]
        if (!i) {
                #  Encountered new attribute.  Record its name for
                #  index lookups, and record its index for name lookups.
                i = nextattr
                attrindex[$5] = i
                attrname[i] = $5
                ++nextattr
        }
        #  Store values by attribute name.
        pkg[i] = $6

Quote:}

END {
        for (i = 1; i < nextattr; ++i) {
                #  If a value was actually stored under this attribute,
                #  print the attribute name and the value.
                val = pkg[i]
                if (val) {
                        if (i > 1)
                                printf("|");
                        printf("%s=%s", attrname[i], val)
                }
        }
        printf("\n")

Quote:}

----
And evidently it's less complex than necessary, because your data
apparently goes on to repeat this analysis.  So you have to figure
out how to get the END block above back into PrintPackageAttrs.

One basic problem here is that awk's array doesn't store an array
as an item, you can't have an array of arrays, so it's a lot more
practical if you can print out your "pkg" array immediately when
it's time to move on to the next one.  If you can't do that - for
example if information for various accounts is interspersed - then
I guess you should convert "pkg" back and forth to a string instead
of writing it out - use split() to get it back.  At any rate, be
sure to clear pkg before reusing it, or you could get spurious data.

        Donn Cave, University Computing Services, University of Washington


 
 
 

1. Tar expertise needed ...

  I have a tape created on solaris 2.3 using the tar facility there and now I am  trying to read the 8mm tape on DEC alpha on OSF/1 using the tar there but for
  some reason I keep getting the error message

     tar: [offset 0]: No space left on device

  Does anybody has an idea on what is going on. How can I read the tape
  successfully. Thanks very much. PLease email at the address above.

  Thanks a lot.

 PS: Yes the tape has been rewinded.

2. Bandwidth management

3. I need someones expertise

4. [Fwd: kerneld problems]

5. script expertise needed

6. Read file contents as variable

7. Need rlogin expertise

8. neeed help on Problem after installation of redhat 5.1 or 5.2

9. Tar expertise needed ...

10. Indianapolis Unix Expertise Needed

11. Need busmouse expertise

12. NEEDED - Solaris expertise

13. Offtopic (sorry) but I need yer expertise