bash - Using ex editor to increment a number following a pattern in a file -


am aware of how use ex editor in syntaxes this answer minor editing of files in place.

for example, mentioned in answer, assuming have file content below:-

$ cat input-file patterngoingdown foo bar foo bar 

running command using ex, like

$ printf "%s\n" '/patterngoingdown' 'd' '/foo' 'n' 'put' 'wq' | ex file $ cat file foo bar foo patterngoingdown bar 

will move pattern patterngoingdown after second occurrence of foo. requirement adopt similar logic increment number after pattern.

example:-

$ cat input-file number number(60) 

is possible use ex editor increment number 60 61like

$ cat input-file number number(61) 

though there ex-editor page available, can't figure out how to

  1. parse next character after search pattern, number in case
  2. increment 61 can via ctrl+a when using vi editor.

i aware there other tools job, particularly need use ex editor in syntax have mentioned.

this tricky because vim not suited this. awk is, posix awk not in place, have use both:

ex -sc '%!awk "\ {\   match(\$0, /[[:digit:]]+/)\   j = substr(\$0, rstart, rlength)\   sub(j, ++j)\ }\ 1\ "' -cx file 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -