Whenever I needed help with “vi” commands, I used to call SriRam . But he has moved to India. I am in trouble. I needed to know how to record and play macro, so I had to do Google search myself. This is so bad. Luckily I found following link http://www.thegeekstuff.com/2009/01/vi-and-vim-macro-tutorial-how-to-record-and-play/ and it was very helpful. This is what I needed to do
We process invoices using AP Invoice interface. In our test instance we needed to run same file multiple times. In order to process same file again and again we needed to change invoice number in the interface file. All invoice fields were separated by pipe character and invoice number was third field. To append “-A” (or something similar like '-B' or '-C') to each invoice number (to make it unique) I used following steps
- Open file in vi
- Go to first line and first character in the file
- Press q (it will start recording keystrokes or macro)
- Press a(you can press any character a to z to give a name to sequences of keystrokes)
- Press / ( to start search in vi)
- Press | and then return (to search pipe character)
- Press n (you will move to second pipe)
- Press n (you will move to third pipe)
- Press i to insert
- Enter –A
- Press ESC key
- Press enter (You will be at first character of second line)
- Press q to stop recording of keystrokes/macro
There were 45712 lines in the file, so by pressing following keys, all invoice numbers were suffixed with “-A”
45711@a
First line was done while recording macro, so I needed to run macro only 45711 times
No comments:
Post a Comment