Increment field? 
Author Message
 Increment field?

AWK can never change the original file directly.  You must output
the modified file and rename the modified file such as:

gawk -v idtag=$current_id '/idtag/{ $2 += 1 }{ print }' datafile.txt


delete datafile.txt
rename datafile.tmp datafile.txt

> Hi all,

> Many thanks for the answers to my last question.  Here's another
> no-brainer I can't seem to find in the FAQ or man page.

> How do I increment the value of a field?

> I was hoping

> gawk -v idtag=$current_id '/idtag/{ $2 += 1 }' ./datafile.txt

> would do it.

> _UNIX in a nutshell_ says awk can "use variables to change the
> database" but all the examples seem to involve printing out things.

> TIA,

> --

> Zoologiska Institutionen                          Ph# +46-8-16-40-37
> Stockholms Universitetet                          Fax +46-8-16-77-15
> Stockholm S-106 91 Sweden            
> http://www.*-*-*.com/

Fri, 18 Feb 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Q: Increment field?

2. Help incrementing print fields

3. Prime record fields on insert - Before adding auto incremented record

4. Incrementing array fields in files

5. Incrementing a numeric field within a GET

6. Spin Box increments less than 1- from .0153 to .98438 w/.0153 increment changes

7. Determining if a field is a substring of another field

8. comparing flat file fields to database fields

9. Dealing with commas as a field separator AND possibly within a field

10. SQLSelect - Loading database/table field data into an Edit field

11. Field names in a field...

12. Field Standards - Setting Standards for cretin types of fields


Powered by phpBB® Forum Software