Skip to main content
5 of 5
edited tags
statox
  • 51.1k
  • 19
  • 158
  • 237

How to replace a space with a colon - command line mode

Input

  • Every line is separated into 8 parts by semicolons
  • Every part can include words,numbers,space etc.

Output

I am trying to replace the space in the 6th part with a semicolon, thus separating the line again, making the total number of parts 9.

Example

1;30;68;Az LEMda;Ads Awdsâ;1 Bethesda, Galilea, Impe Mkals;29;63 264;16 October 1978;2 April 2005;AAz Jgfg adal II;Madwl Qózca Asdtyła;20 May 1920 Maklo, Polasn;58;84 

would end up like

1;30;68;Az LEMda;Ads Awdsâ;1;Bethesda, Galilea, Impe Mkals;29;63 264;16 October 1978;2 April 2005;AAz Jgfg adal II;Madwl Qózca Asdtyła;20;May 1920 Maklo, Polasn;58;84 

Attempts

I tried to find the space using anything ranging from regex to \zs but failed. The closest I came was finding the 5th semicolon.

%s/\(.\{-};\zs\)\{5}/;/g 

But I need to find the space that comes after the number that comes after the 5th semicolon, so this kind of thinking got me nowhere and now I am trying to find the space in the parts that I defined earlier.

I could put awk into vim but then again I am fairly new with it. I managed to find the 6th part and change the space into a semicolon, but then it changes all the spaces, not just the first one.

:%! awk 'BEGIN{FS=OFS=";"} {gsub(/ /, ";", $6)} 1' 

How can I just change the first space in the 6th part?

arty
  • 145
  • 1
  • 6