It's not the Network! Ok, maybe it's the network...

Jason Rahm

Subscribe to Jason Rahm: eMailAlertsEmail Alerts
Get Jason Rahm: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Google

Blog Feed Post

The ABCs of NSM - V is for Vim

Welcome back for another episode of the ABC's of NSM.  What's NSM you say?  We'll go with Network and System Management, but you abc_2_4 could throw Security in there as well.  We'll work our way through the alphabet over  the next several weeks looking at  tools and concepts along the way for all the administrators out there.   By the way, you can thank Joe for the format & Don for the title  (I  couldn't for the life of me come up with one.)

Today's letter V is for Vim. Vim is a cross-platform console and GUI text editor that is backwards compatible with the unix shell vi, from which it gets its name (Vi Improved).  There are an abundance of features in Vim that are not in vi, but mostly I like Vim for the syntax highlighting and the unlimited undo.  Other than that, Vim or vi, doesn't much matter to me--as long as one is available.  There is a learning curve with vi, but like any good tool, whole new worlds open up to you once you are comfortable with the basics.  Besides, editing text in vi is just plain fun.  And I'm always learning something new.  Just yesterday I was trying to find all occurrences of a string that started and ended the same but had two characters that changed (representing an object type).  I knew already how to find this string: hash_..0019.  What I didn't know how to do was to avoid changing the two unique characters in the middle of the string when I did the global replace.  Enter grouping.  By grouping parts of the string in your search parameters, you can then print the desired group as is and just change the necessary part:

Original Strings: hash_010019, hash_050019, hash_090019, hash_100019

Final String: hash_010014, hash050014, hash_090014, hash_100014

Vi Command: :%s/\(hash_..\)\(0019\)/\10014/g

Breaking that down, we have:

:%s/<search string>/<replace string>/g

The search string is broken in two groups: hash_.. & 0019 (The parentheses are escaped)

The replace string is \1 for the first group, and then I want the 0019 replaced with 0014.

Vi is cool, isn't it?

 

Follow me on Twitter Follow me on LinkedIn Follow me on Facebook Add to Technorati Favorites

 

 

Read the original blog entry...

More Stories By Jason Rahm

Experienced predominantly in the networking realm over the last dozen or so years, Jason is expanding his horizons towards systems management and even trying his hand at python.

Jason assists in the maintenance duties for http://devcentral.f5.com, contributes frequently in the forums, and writes weekly on some cool geekery in the F5 product lines. When not working, Jason enjoys spending time with his beautiful wife Michelle and his four children. He is active and volunteers network administration duties at his church and if there are any remaining minutes in the week, he enjoys Wii & XBOX, tennis, racquetball, softball, etc. He does not enjoy running, but does (scratch that, thinks about doing) it anyway to recover his youthful appearance.