Update fields questions 
Author Message
 Update fields questions

Hi.

I am trying to find a way to update 3 fields in a record.  If the
three fields are zeros, then update the values of those fields
to the values in the previous record.  For example, I have 8
comma-delimited fields and every few records, fields 6 through 8
are zero.

100,101,102,ny,ny,4200,5200,6200
100,101,105,ny,ny,0,0,0
102,103,104,ny,ny,0,0,0
200,201,201,text,wi,900,500,600
200,201,202,text,wi,0,0,0

With the above example, I would want to update fields 6-8 in records
2 and 3 with the 6-8 fields in record 1.  Any help with pointing
me in the correct direction would be greatly appreciated.

TIA,

Geoff



Sat, 25 Mar 2000 03:00:00 GMT  
 Update fields questions

BEGIN { FS = "," }

{
    for ( i = 1; i <= NF; i++ )
    {
        if ( $i == 0 )
            $i = old[i]
        else
            old[i] = $i

        if ( i > 1 )
            printf( "," );

        printf( "%s", $i );
    }

    print ""

Quote:
}

--
Best regards,
 _ __                      _    ,   _ _ _
' )  )     /         _/_  ' )  /   ' ) ) )
 /--' ____/___/> __  /     /--/     / / / __,_  __  o _   ______
/  \_(_) /_) (__/ (_<__   /  ( o   / ' (_(_) (_/ (_<_/_)_(_) / <_

Robert H. Morrison                      Tel:   +49 721 9628 167
Software Development, Basis Team        FAX:   +49 721 9628 261



Quote:
> Hi.

> I am trying to find a way to update 3 fields in a record.  If the
> three fields are zeros, then update the values of those fields
> to the values in the previous record.  For example, I have 8
> comma-delimited fields and every few records, fields 6 through 8
> are zero.

> 100,101,102,ny,ny,4200,5200,6200
> 100,101,105,ny,ny,0,0,0
> 102,103,104,ny,ny,0,0,0
> 200,201,201,text,wi,900,500,600
> 200,201,202,text,wi,0,0,0

> With the above example, I would want to update fields 6-8 in records
> 2 and 3 with the 6-8 fields in record 1.  Any help with pointing
> me in the correct direction would be greatly appreciated.

> TIA,

> Geoff




Sat, 25 Mar 2000 03:00:00 GMT  
 Update fields questions


[...[
% For example, I have 8 comma-delimited fields and every few records,
% fields 6 through 8 are zero.
%
% 100,101,102,ny,ny,4200,5200,6200
% 100,101,105,ny,ny,0,0,0
% 102,103,104,ny,ny,0,0,0
[...]

% With the above example, I would want to update fields 6-8 in records
% 2 and 3 with the 6-8 fields in record 1.

Just do something like this:
 BEGIN {
   # fields are comma-delimited
   FS = ","
   OFS = ","

   # might want to set up some default save[] values here
 }

 {
   # if the last three fields are all 0, replace with saved values
   if (!$6 && !$7 && !$8) {
      for (i = 6; i < 9; i++) $i = save[i]
   }
   # otherwise save those values
   else {
      for (i = 6; i < 9; i++) save[i] = $i
   }

   # now print the resulting record
   print
 }

Hope that helps.
--

Patrick TJ McPhee
East York  Canada



Sun, 26 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C4 - updating an entry field - simple question

2. Reading a Field and Updating a Field in Another File

3. getting autoincrementing key to update child field in code

4. Updating db fields from combo box

5. Can't Update fields

6. Variable-updating in entry-field

7. Need help updating a field!!

8. How to update Browse table from entry field?

9. Updating total field

10. Updating date/time fields in generic abc file manager class

11. Sharing a display field on an update form

12. Update fields and Strip

 

 
Powered by phpBB® Forum Software