Q: Increment field? 
Author Message
 Q: Increment field?

|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.

Two main errors here. The first is a conceptual problem - your script
reads data in from a file (fairly implicitly), and conditionally alters
it. It does not output anything, therefore running it will have no
effect. The second is that you cannot use variables in regexs in that
manner. The sort of thing you could do is:

gawk '/'$current_id'/ {$2++} {print}' ./datafile.txt > newdatafile.txt



PO Box 220, Whiteknights, Reading, | Phone: +44-118-9875123 ext 7594
Berkshire, RG6 6AF, United Kingdom | Fax:   +44-118-9750203                
WWW: http://www.*-*-*.com/ ~spr96phh/pete.html Use lynx - you know you want to!

Mon, 14 Feb 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Help incrementing print fields

2. Increment field?

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. several Qs

8. Qs on CLUBMGR, Template BUG ???

9. Qs

10. Qs about language nomenclature

11. New newbies Qs on Ruby

12. Newbie Qs: startup time, Module.constants, chdir, Ruby distro's library


Powered by phpBB® Forum Software