[nSLUG] gawk... @#^&##&^!!- ;-)

David Potter dlpotter at eastlink.ca
Thu Mar 11 17:46:22 AST 2010


OK... big head shake - it has been along time... ;-)

Thanks

David


Jason Kenney wrote:
> We just meant that variables in awk are not referenced using a '$' at
> all, so when you say '$new_id' or '$hash' it should really be 'new_id'
> or 'hash' (like you have further down in your code - you only made the
> mistake once for each case).  The '$' is reserved for references the
> fields of a record...
>
> What I think is producing the error you see is this:
>
> I think awk is substituting the variable new_id (or alternatively the
> variable here, it doesn't matter which) for its 'value'.  I believe
> that the 'value' is the address for the start of the string (as if you
> were printing out a pointer variable in C for example) - and then
> trying to parse '$[pointer address]' which I guess comes out negative
> because awk is making assumptions about signedness and thus you get
> the error for an invalid field (a negative one).
>
>
> Jason
>
> On Thu, Mar 11, 2010 at 5:08 PM, David Potter <dlpotter at eastlink.ca
> <mailto:dlpotter at eastlink.ca>> wrote:
>
>     Hi Jason/George...
>
>     I haven't trotted out gawk for a long time and so, as expected,  I
>     was struggling with syntax errors. So I had reduced the code down
>     to try and identify the problem(s).  I had been using a BEGIN
>     section to initialize the variables to "".
>
>     I agree that the first record would never produce correct
>     output... but it only has to save $1 and $3 because the first real
>     test is the second record.
>
>     When the match to $1 is found, I'm trying to capture both the old
>     id ($3 from the previous record) and new 'id'.
>
>     And the lack of proper output didn't explain (to me) the fatal
>     error on the 19th record...?
>
>     David
>
>
>
>     Jason Kenney wrote:
>>     But $new_id should also be new_id as well, which is why that output is
>>     missing.  I'm sure you're way ahead of me though.  :)
>>
>>
>>     Jason
>>
>>     On Thu, Mar 11, 2010 at 4:26 PM, George N. White III <gnwiii at gmail.com> <mailto:gnwiii at gmail.com> wrote:
>>       
>>>     On Thu, Mar 11, 2010 at 4:21 PM, Jason Kenney <jdkenney at gmail.com> <mailto:jdkenney at gmail.com> wrote:
>>>         
>>>>     It just looks like bad syntax to me  :)
>>>>
>>>>     You have $hash instead of just hash in the first place you use it.
>>>>           
>>>     I second this suggestion.  With just the deletion of one '$' the output is:
>>>
>>>     0005b186aaaf0114b60685e2ea5a1a41:new:33619
>>>     0008d656ad44e3167a673d5859c23aa8:new:20788
>>>     0008d656ad44e3167a673d5859c23aa8:old:01123
>>>     new::old:01123
>>>     000e63eefbd422fb00c73cd3fcd034d8:new:13135
>>>     00106f312cdfa88965c2d9d6d933a144:new:05629
>>>     0012c059f0b1a4ae7ca31f09d643d0db:new:12496
>>>     00161f484478012ee57f309ae79f4111:new:32212
>>>     0018f8aba382f6b4a04e7f29031e0e58:new:10048
>>>     0018f8aba382f6b4a04e7f29031e0e58:old:05921
>>>     new::old:05921
>>>     0019cd240cd81f41607f7b60eaf86ec2:new:36133
>>>     0019cd240cd81f41607f7b60eaf86ec2:old:04200
>>>     new::old:04200
>>>     001dd3feb1716aadc0ac50f8f3371feb:new:39733
>>>     001fa91f4dcbae90e6a33c51aea620c9:new:24385
>>>     002c181d94759cada0b629bf91e51015:new:41545
>>>     002ded4193a37217568d0e93ba776498:new:35305
>>>     002e3cd58b2efe701dc6517d5998a7cf:new:07687
>>>     002e3cd58b2efe701dc6517d5998a7cf:old:03802
>>>     new::old:03802
>>>     002e959175c5e73273752e743c2536bf:new:17593
>>>     002e959175c5e73273752e743c2536bf:old:03161
>>>     new::old:03161
>>>     002ff56b75a72bdcca401ff9bba14907:new:35167
>>>
>>>
>>>         
>>>>     Jason
>>>>
>>>>     On Thu, Mar 11, 2010 at 4:11 PM, David Potter <dlpotter at eastlink.ca> <mailto:dlpotter at eastlink.ca> wrote:
>>>>           
>>>>>     My poor, old, head is fried so I'll not suggest the logic is correct. I'm
>>>>>     trying to find records that have $1 identical , save  $3 from the first (as
>>>>>     new record number) and sent the new record# and the old record# to output.
>>>>>
>>>>>     I'm getting an odd, recurring error that has me wondering if there is a bug
>>>>>     in this version of gawk - I know, I know... poor workman to blame the
>>>>>     tools... ;-)
>>>>>
>>>>>     Data in:
>>>>>
>>>>>     0005b186aaaf0114b60685e2ea5a1a41  -:new:33619
>>>>>     0008d656ad44e3167a673d5859c23aa8  -:new:20788
>>>>>     0008d656ad44e3167a673d5859c23aa8  -:old:01123
>>>>>     000e63eefbd422fb00c73cd3fcd034d8  -:new:13135
>>>>>     00106f312cdfa88965c2d9d6d933a144  -:new:05629
>>>>>     0012c059f0b1a4ae7ca31f09d643d0db  -:new:12496
>>>>>     00161f484478012ee57f309ae79f4111  -:new:32212
>>>>>     0018f8aba382f6b4a04e7f29031e0e58  -:new:10048
>>>>>     0018f8aba382f6b4a04e7f29031e0e58  -:old:05921
>>>>>     0019cd240cd81f41607f7b60eaf86ec2  -:new:36133
>>>>>     0019cd240cd81f41607f7b60eaf86ec2  -:old:04200
>>>>>     001dd3feb1716aadc0ac50f8f3371feb  -:new:39733
>>>>>     001fa91f4dcbae90e6a33c51aea620c9  -:new:24385
>>>>>     002c181d94759cada0b629bf91e51015  -:new:41545
>>>>>     002ded4193a37217568d0e93ba776498  -:new:35305
>>>>>     002e3cd58b2efe701dc6517d5998a7cf  -:new:07687
>>>>>     002e3cd58b2efe701dc6517d5998a7cf  -:old:03802
>>>>>     002e959175c5e73273752e743c2536bf  -:new:17593
>>>>>     002e959175c5e73273752e743c2536bf  -:old:03161
>>>>>     002ff56b75a72bdcca401ff9bba14907  -:new:35167
>>>>>
>>>>>     Ubuntu - gawk
>>>>>
>>>>>     #!/bin/bash
>>>>>
>>>>>     cat /tmp/hash_combined | sed -e 's/[ \t\-]*//g' | gawk -F: '
>>>>>     {
>>>>>
>>>>>     # testing...
>>>>>     print $0
>>>>>     # end testing...
>>>>>
>>>>>     if ($hash == $1) { printf("new:%s:old:%s\n", $new_id, $3);
>>>>>     hash=$1; new_id=$3; next; }
>>>>>
>>>>>     else { hash=$1; new_id=$3; next; }
>>>>>
>>>>>     }'
>>>>>
>>>>>     Output
>>>>>
>>>>>     0005b186aaaf0114b60685e2ea5a1a41:new:33619
>>>>>     0008d656ad44e3167a673d5859c23aa8:new:20788
>>>>>     0008d656ad44e3167a673d5859c23aa8:old:01123
>>>>>     000e63eefbd422fb00c73cd3fcd034d8:new:13135
>>>>>     00106f312cdfa88965c2d9d6d933a144:new:05629
>>>>>     0012c059f0b1a4ae7ca31f09d643d0db:new:12496
>>>>>     00161f484478012ee57f309ae79f4111:new:32212
>>>>>     0018f8aba382f6b4a04e7f29031e0e58:new:10048
>>>>>     0018f8aba382f6b4a04e7f29031e0e58:old:05921
>>>>>     0019cd240cd81f41607f7b60eaf86ec2:new:36133
>>>>>     0019cd240cd81f41607f7b60eaf86ec2:old:04200
>>>>>     001dd3feb1716aadc0ac50f8f3371feb:new:39733
>>>>>     001fa91f4dcbae90e6a33c51aea620c9:new:24385
>>>>>     new::old:24385
>>>>>     002c181d94759cada0b629bf91e51015:new:41545
>>>>>     new::old:41545
>>>>>     002ded4193a37217568d0e93ba776498:new:35305
>>>>>     002e3cd58b2efe701dc6517d5998a7cf:new:07687
>>>>>     002e3cd58b2efe701dc6517d5998a7cf:old:03802
>>>>>     002e959175c5e73273752e743c2536bf:new:17593
>>>>>     002e959175c5e73273752e743c2536bf:old:03161
>>>>>     gawk: cmd. line:11: (FILENAME=- FNR=19) fatal: attempt to access field
>>>>>     -2147483648
>>>>>
>>>>>
>>>>>     _______________________________________________
>>>>>     nSLUG mailing list
>>>>>     nSLUG at nslug.ns.ca <mailto:nSLUG at nslug.ns.ca>
>>>>>     http://nslug.ns.ca/mailman/listinfo/nslug
>>>>>
>>>>>
>>>>>             
>>>>     _______________________________________________
>>>>     nSLUG mailing list
>>>>     nSLUG at nslug.ns.ca <mailto:nSLUG at nslug.ns.ca>
>>>>     http://nslug.ns.ca/mailman/listinfo/nslug
>>>>
>>>>           
>>>     --
>>>     George N. White III <aa056 at chebucto.ns.ca> <mailto:aa056 at chebucto.ns.ca>
>>>     Head of St. Margarets Bay, Nova Scotia
>>>     _______________________________________________
>>>     nSLUG mailing list
>>>     nSLUG at nslug.ns.ca <mailto:nSLUG at nslug.ns.ca>
>>>     http://nslug.ns.ca/mailman/listinfo/nslug
>>>
>>>         
>>     _______________________________________________
>>     nSLUG mailing list
>>     nSLUG at nslug.ns.ca <mailto:nSLUG at nslug.ns.ca>
>>     http://nslug.ns.ca/mailman/listinfo/nslug
>>
>>       
>
>
>     -- 
>
>
>     _______________________________________________
>     nSLUG mailing list
>     nSLUG at nslug.ns.ca <mailto:nSLUG at nslug.ns.ca>
>     http://nslug.ns.ca/mailman/listinfo/nslug
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug
>   


-- 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nslug.ns.ca/mailman/private/nslug/attachments/20100311/68a2e650/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2007-Bench.jpg
Type: image/jpeg
Size: 17251 bytes
Desc: not available
URL: <http://nslug.ns.ca/mailman/private/nslug/attachments/20100311/68a2e650/attachment-0002.jpg>


More information about the nSLUG mailing list