help me..... 
Author Message
 help me.....

Ok..so I got this thing to do everything I want it to but:

I need for it to know how many times it recieves the same first field
from a presorted file and add that number on to the end of the line with
the word references after that.

so if it recieves a file with the following two lines

booger  97
booger 99

it will print:

1    booger 97, 99       2 references

it seems like getline is what I need but I am not sure....here is what I
have.  And thanx for your help.

BEGIN {
         printf( "INDEX \n")
      }

NF != 2 || $2 !~ /^[0-9]+$/ { next }

$1 == pre {
            ++o
            printf(", %s",$2)
          }

$1 != pre {
           if (i>0)
              {
                ++o
                ++l
                printf("\n%d\t%s\t%s",l,$1,$2)
              }
           else
              {
               ++o
               ++l
               printf("%d\t%s\t%s",l,$1,$2); i=1
              };
           pre = $1
          }

END{
     printf("\nEND-OF-INDEX\n" )
   }



Fri, 31 Mar 2000 03:00:00 GMT  
 help me.....

Quote:

> Ok..so I got this thing to do everything I want it to but:

> I need for it to know how many times it recieves the same first field
> from a presorted file and add that number on to the end of the line with
> the word references after that.

> so if it recieves a file with the following two lines

> booger  97
> booger 99

> it will print:

> 1    booger 97, 99       2 references

Your solution is far too difficult. Try the following:
pre!=$1 { if(n>0) printf("  %d references\n",n)
          n = 0
          pre = $1
          printf("%s  ",pre)
          delim = ""
        }
        { n++
          printf("%s%s",delim,$2)
          delim = ", "
        }
END     { printf("  %d references\n",n) }

While untested, this approximately correct. Its biggest error it the
unlimited line length of the output file if there are a large number of
references to the same first word value. This could be handled best in a
pretty printer second phase. Always small, correct programs glued
together to achieve a large objective

The three commands handle the three cases: a new word; the same word;
and the end of file. In the new word case we must print out the old
reference count if there is one and start a new line; then start the new
line for the new word and initialize the separator for the references
and the counter. In the same word case, count the reference, print the
reference and arrange the delimiter for 2nd-nth references. In the end
file case, print the reference case for the final word.

--
Bob Stearns
University of Georgia

(706)542-5110



Fri, 31 Mar 2000 03:00:00 GMT  
 help me.....



Quote:
>Ok..so I got this thing to do everything I want it to but:

>I need for it to know how many times it recieves the same first field
>from a presorted file and add that number on to the end of the line with
>the word references after that.

>so if it recieves a file with the following two lines

>booger  97
>booger 99

>it will print:

>1    booger 97, 99       2 references

Could you use the associative array. The file need not even be sorted
{
 a[$1]= a[$1] "," $2}
END {for (i in a) print i, a[i], split(a[i], junk, ",") "references"}

Not perfect/correct and it hasnt been tested, but it gives you the basic idea...
Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.efiche.com/efiche **



Fri, 31 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. help! f90.help help help help

2. ***HELP***HELP***NEED INFORMATION***HELP***HELP

3. HELP HELP HELP HELP

4. HELP HELP HELP HELP

5. Ord Function HELP Please HELP HELP HELP

6. help help help help!!!!!!!!!!!

7. (HELP (HELP (HELP (HELP))))

8. HELP: HELP: HELP: HELP: Online-manual on Expect

9. Help Help Help

10. TopSpeed - ODBC 3.1???? HELP HELP HELP

11. HELP - HELP - HELP

12. HELP HELP HELP - round function error

 

 
Powered by phpBB® Forum Software