[PLUG] Correcting duplicate strings in files [RESOLVED]

Robert Citek robert.citek at gmail.com
Tue Jun 19 17:26:49 PDT 2018


Awk is a very nice "little" language.  Glad to hear it worked.  And
thanks for letting us know. - Robert

On Tue, Jun 19, 2018 at 4:58 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> On Tue, 19 Jun 2018, Robert Citek wrote:
>
>> $2 != "16.00" { print ; next }  <= the decimal should be a colon, 16:00 vs
>> 16.00
>
>
> Robert,
>
>   Oy! Too often we see what we expect to see, not what's actually there. I
> had that in a FORTRAN IV program in the early 1970s.
>
>> flag == 1 && $2 == "16:00" { $2=="17:00"; print; flag=0 ; next } <=
>> equality should be assignment, $2= vs $2==
>
>
>   Ah, I missed that completely, as well as the order of pattern tests.
>
>> Here's a refactored version that you can put in a file:
>>
>> BEGIN {OFS=FS=","} ;
>> flag == 1 && $2 == "16:00" { $2 = "17:00" ; flag = 0 } ;
>> $2 == "16:00" { flag = 1 } ;
>> { print } ;
>
>
>   And it works. Thanks for teaching me a tool that will be applied to other
> awk scripts.
>
>> BTW, in your sample data set the 15:00 and 16:00 entries are identical
>> in the last field.  Is that expected or coincidental?
>
>
>   Expected. This is river stage height data (the elevation of the water
> surface) and it may be constant for a while, or vary fairly regularly. What
> I'm interested in is the pattern cycles: diurnal, seasonal, and annual.
>
> Best regards,
>
> Rich
> _______________________________________________
> PLUG mailing list
> PLUG at pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug


More information about the PLUG mailing list