# Learning to work with vi



## Nosada (Oct 30, 2009)

Hey all, after losing my job and re-inrolling in university (long story) I'm currently catching up to a class in Unix programming.

I'm stumped by a few commands though and I thought there might be a helpful, bored, willing soul here on TPU 

First problem:

I get a file with mortality rates per country, per year. I need to join every line per country. I have 2 lines per country. :16,17j works obviously, but that way I have to manually do every country. Only 6 countries in list, so not really much work, but I doubt this is what the prof intended.

Second problem:

Once they are joined, I have to re-order the contents.

Belgium 06 61,0 111,0
Belgium 00 68,0 130,0

should become

Belgium 61,0(06)-68,0(00) 111,0(06)-130,0(00)

for that I'm using, in vi:
:16,$s/\([a-z]*\) \([0-9]*\) \([0-9]*\,[0-9]\) \([0-9]*\,[0-9]\) \([a-z]*\) \([0-9]*\) \([0-9]*\,[0-9]\) \([0-9]*\,[0-9]\)/\1 \3(\2)-\7(\6) \4(\2)-\8(\6)

but that just gives me E486: patter not found error. As a regular expression, I'm pretty sure it's correct, but vi probably isn't capable of reading it as I want it to.

Any resident editor specialist mind taking a swing at this?


----------



## Zedicus (Oct 30, 2009)

just checking basics here but you are in the correct mode?  command vs. insert?
im by no means a vi coder, i prefer pretty much any other editor/interpreter. 
also maybe you could script it into chunks and then set the chunks as variables and use that to place things in correct order?
again im sort of shooting in the dark here, im not even 50% sure i understand what your trying to accomplish.
any more details???


note:  looking up a vi cheat sheet leads me to believe you need to encapsulate your commas as you are tying to use them as just basic text to add to your information.   again i may not even understand entirely what your goal is.  also incase you missed this "im by no means a vi coder, i prefer pretty much any other editor/interpreter. "

  but no one else has posted, maybe a vi guru will jump in.


----------

