Friday, 5 October 2012

Getting to grips with …. vi

I'm almost ashamed to admit that I'm still somewhat of a newbie when it comes to vi, but, like Manual, I come from Barcelona I learn.

I have blogged about vi before, and have also reviewed the Wikipedia page ( hasn't everyone ? ). There's also this: -


However, I'm grateful to one of my colleagues for showing me how one may search/replace in vi rather than, as I used to do, cheating and starting a GUI editor ( kate, gedit, tedit etc. ). This is especially useful where X11 is not available to one.

So, I wanted to replace the phrase AppServer_1 with AppServer in a response file: -

$ vi installWAS85.rsp

:1,$ s/AppServer_1/AppServer/g

This is broken down as follows: -

: Bring up the vi command line
1,$ Start at the first column, continue until the end of the line
s/ Start search
AppServer_1 Word to search for
/ Separator
AppServer Word to replace with
/g End search

Simples :-)

2 comments:

Ryanm29 said...

Hi Dave,

Wouldn't this have been easier?

:%s/AppServer_1/AppServer/g

that said, between the lines is a good one I didnt know.

Dave Hay said...

@Ryan - cheers, I guess it goes to show that there's more than one way to skin a vi command :-)

Note to self - use kubectl to query images in a pod or deployment

In both cases, we use JSON ... For a deployment, we can do this: - kubectl get deployment foobar --namespace snafu --output jsonpath="{...