bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interaction between $0 and substr


From: Aharon Robbins
Subject: Re: Interaction between $0 and substr
Date: Fri, 12 Jan 2007 14:21:17 +0200

Greetings. Apologies for the delay in replying, but I've not had much
time for gawk lately.

I looked at this. First, gawk 3.1.1 is quite old, you should upgrade. Second,
I cannot reproduce this with a current version.

Your best source for current gawk code is the CVS archive at savannah.gnu.org.

Best of luck,

Arnold Robbins

> Date: Tue, 07 Nov 2006 10:50:09 -0500
> From: Claude Williams <address@hidden>
> Subject: Interaction between $0 and substr
> To: address@hidden
>
> I am using GNU awk 3.1.1 on a Linux Redhat Enterprize workstation.
>
> I have found a problem in the GAWK programming language involving the 
> use of the incoming record ($0) and its interaction with certain 
> internal functions. For instance, if you are parsing a line using the 
> substr function such as:
>
> BEGIN {
>  istrt = 12
>  ilen = 6
>  incr = 7
> }
>
> {
>  for(im = 1; im <= 12; im++)
>  {
>    ic = istrt + (im-1)*incr
>    val = substr($0, ic, ilen) + 0
>    sdata += val
>    snum ++
>  }
>  ...
>  print $0
> }
>
> If any of the substr fields is "     0", this part of the string is NOT 
> printed out as part of $0.
>
> Example:
> Input:
> 170814 1993   117      0    195    365    494    583    642    649    
> 541    375    300    176      0   370
> Output:
> 170814 1993   117     195    365    494    583    642    649    541    
> 375    300    176    370
>
> To remedy this problem, I set a temporary string to the input record 
> (rec = $0), and when I need to print out the original record (print rec).
>
> Claude




reply via email to

[Prev in Thread] Current Thread [Next in Thread]