Blog This!   Lee Geistlinger's Web Log
Blog Home
Blog Archives
LittleGhost Home

E-mail: geistlinger AT gmail.com

Loading
Pic 'O the Day
Top 10 Lists
Everyone loves lists
Reviews
Books, Movies and so on
Blogroll
Feed Me!

XML Feed

Feeds I Read

My Online Aggregator

Theme
• Default
• Spring
• Summer
• Autumn
• Winter
• Black & White
• Gray & White
• MT-ish
• Classic
Listening To...
Evidence of Efforts

This page is powered by Blogger. Isn't yours?

Valid CSS!

[Valid RSS]

Recent Posts
 Sunday, December 14, 2008
Stupid vi Tricks

I'm writing this up to help others, and so I can refer to it again.

Long story, but at work I was left with a text file that was a comma-delimited list that had:

Example lines:
12345,20081107,John Smith, 123 Main Street....
23456,20081108,Fred Thomas, 44 Pine...
66666,20081201,Jill Harvey, 234 Thomas Ave...

(The ellipsis [...] is just a placeholder for the additional customer info, plus line feed.)

I wanted to do a quick transformation on this list and extract a list of Order IDs only. I was in vi (I had grepped this list out of a bigger list; long story that I'm not going to bore you with).

Now, the first set of data was the order IDs, and the second was repeated in every line (,2008[whatever]).

So, it seemed trivial to do a REGEX to find this repeating element in every line, and remove it and all that follows to end of line.

Seems simple, but it took three of us a half-hour of monkeying around and googling before we found the solution, which is:
:%s/,2008\p*//

At the replace prompt (:), run substitute against all lines (%s).

Find the repeating item(,2008) and replace that and all (*) printable characters (\p)that follow (\p*) with nothing (//)

End up with a list of order IDs, as desired.
12345
23456
66666

Trivial now; just had to find the correct REGEX to replace all that follows that pattern.

This has been a Public Service Announcement from Stupid vi Tricks....

- Posted by Lee at 2:13 PM Permalink #
^Top | Top Ten Home | Blog This! Home | Blog This! Archives