> I periodically need to make changes to a script built with tab  
> delimited values. 

Looking at your script sample, I must be missing the tab delims...

> What I need to do is, from time to time, to either  
> add 1 to a value or to subtract 1 from the same value.  Typically the  
> script looks like:
> 
> ln 1 $10 !="" { printf "((moodlook " $10 }
> ln 2 $11 !="" { printf "((feeloil " $11 }
> ln 3 $12 !="" { printf "((eyeflavor " $12 }
> .  .  .
> 
> Is there an alternative to manually CTRL-A'ing each line twice to  
> change ln 1, for example, to
> 
> #11 !="" { printf "((moodlook " $11 }


I think you could get away with something like this one-liner
(broken into several lines for clarity)

:%s
/$\(\d\+\)\( !="" { printf "((\w* " $\)\(\d\+\)
/\=(submatch(1)+1).submatch(2).(submatch(3)+1)
/g

It should find any matches of the pattern defined in the first
line and increment each of the two numbers by 1.  Change the two
instances of "+1" to "-1" or whatever math you want to perform on
them.  If you want to ensure consistency, you can change it to

:%s
/$\(\d\+\)\( !="" { printf "((\w* " $\)\1
/\=(submatch(1)+1).submatch(2).(submatch(1)+1)
/g

This will refuse to change lines where, for some reason the first
variable is different from the second one.

If you have problems with it, or something is making you scratch
your head, write the list back with questions and I can 'splain it.

HTH,

-tim



Reply via email to