Reputation: 140
I need to increment the numbers form a file using awk/sed/... .
file:
step0=action_a
step1=action_b
step2=action_c
output:
step1=action_a
step2=action_b
step3=action_c
I've tried with:
awk '/step/{ $2=$2+1 }' file
but the step numbers are not incremented.
Upvotes: 3
Views: 455
Reputation: 195229
awk can do it for sure. however, with vim, your problem could be solved very easily.
vim -c "%norm! ^A" file
the ^A
you press Ctrl-V Ctrl-A
then check the changed text in your vim, if you are satisfied, then press :wq
save the file and quit.
If this is not the answer you are looking for, let me know, I would remove the answer.
Upvotes: 1
Reputation: 33387
Using Ed Morton's answer on a similar question, you could do it like this:
$ awk -F'[^[:digit:]]+' '{sub(/[[:digit:]]+/,$2+1)}1' file
step1=action_a
step2=action_b
step3=action_c
This replaces the first number (i.e. sequence of digits) with the matched number plus one.
Upvotes: 2