1

Still a regular expressions newb but I'm still learning. What I would like to do is replace the number '1' in bold here using Vim and regular expressions. But the catch is that it has to do it not only for this line, but for every line ON THIS VERY POSITION. So in other words, this '1' happens to be in the 29th space on my flat file. I want to change it to '2'. Can anyone lend me a hand? Thank you in advance.

2017033112xxxxxxxxx19420525212007

Galidari
  • 43
  • 1
  • 8

3 Answers3

3
%s/\%29c[0-9]/2/g

It will find any number (from 0 to 9) in the 29th column and replace it with 2.

Jose Reyes
  • 101
  • 5
2
%s/^\(.\{28}\)1/\12/

This will preserve the first 28 characters of each line, and replace the '1' in the 29th position with a '2'

Chris Rouffer
  • 743
  • 5
  • 14
  • This is great. Thanks Chris! I can see where I where it basically escapes everything up to the 28th character, now. – Galidari May 03 '17 at 20:35
2

Changes 1's in the 29th position to 2 using match start \zs

%s/^.\{28\}\zs1/2

before

123456789012345678901234567890123
2017033112xxxxxxxxx19420525212007
2017033112xxxxxxxxx19420525292006
2017033112xxxxxxxxx19420525212005

after

123456789012345678901234567890123
2017033112xxxxxxxxx19420525222007
2017033112xxxxxxxxx19420525292006
2017033112xxxxxxxxx19420525222005
Jim U
  • 3,318
  • 1
  • 14
  • 24