1849796 Members
2537 Online
104044 Solutions
New Discussion

Re: Vi Editor !!!!!

 
Justin_132
Advisor

Vi Editor !!!!!

Hi Admins,

I gotta some wkrs with vi..Cud somebody throw some lights on "searching a WORD and deleting the line containing that word"...

Any links/stuff whers I can understand more tricks with good examples..

Thxs n advance,
Just-In
12 REPLIES 12
A. Clay Stephenson
Acclaimed Contributor

Re: Vi Editor !!!!!

Although decades old, vi is still a powerful editor although the kinds of task you describe are usually done with sed.


http://www.lagmonster.org/docs/vi.html
If it ain't broke, I can fix that.
Hein van den Heuvel
Honored Contributor

Re: Vi Editor !!!!!

Well, in VI I just hit "/WORD" or toss in some spaces/whitespace regexpr. Now hit 'dd'.

But I suspect you want more? Like all lines in the file that match? Or like put the whole think in a script?

I would suggest the sed editor for that job instead of vi. Is is more script oriented imho.

But why not simply use:
$ grep -v WORD file-with-word > file-without-word.

Again, add -E or wordboundaies as needed

If GREP can not do the job, then please explain why not. Know that, someone may be able to resolve it, or may be able to come up with a better vi or sed solution based on a refined problem description.

fwiw,
Hein.

James R. Ferguson
Acclaimed Contributor

Re: Vi Editor !!!!!

Hi Justin:

Here's a brief, basic introduction to using 'vi':

http://docs.hp.com/en/A2615-90003/ch17.html

Of course, the standard first-line-of-defense cam always be found in the manpages:

http://www.docs.hp.com/en/B2355-60103/vi.1.html

For your question:

:/word
dw

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: Vi Editor !!!!!

Hi,

For searching a word in vi, Go to command mode
/word
Curser will on the word. You can delete the entire line by 'dd'(without quote)

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Arunvijai_4
Honored Contributor

Re: Vi Editor !!!!!

Hello,

As always, take a look at "man vi" for complete listing of commands and this link should be helpful...

http://www.chem.brown.edu/instructions/vi.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
James R. Ferguson
Acclaimed Contributor

Re: Vi Editor !!!!!

Arun:

I am mystified as to why you (and some other individuals) post the same answers hours or days after other participants. I am mystified why your posts are divided into multiple ones usually minutes apart.

Please read what has alraedy been written in a post and think a little before you write. We need fresh information, not a "me too".

...JRF...

Arunvijai_4
Honored Contributor

Re: Vi Editor !!!!!

Hi James,

I am mystified as to why you (and some other individuals) post the same answers hours or days after other participants. I am mystified why your posts are divided into multiple ones usually minutes apart.

*** My long posts are not getting into forums.. Thats why i prefer short answers. When i post long answers, i always get Error posting message. May be i need to change my browser from Firefox.. Even, Muthukumar has this problem from his machine.


Please read what has alraedy been written in a post and think a little before you write. We need fresh information, not a "me too".

***I gave a fresh information that defers from what others gave (I used "dd" to delete where your was "dw").

Thanks,
Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Hein van den Heuvel
Honored Contributor

Re: Vi Editor !!!!!

JRF wrote ...

"... I am mystified as to why you (and some other individuals) post the same answers hours or days after other participants ..."

Ditto.
It ads no value and it distracts.
Myself, and other also I suspect, keep following topics where we opted to reply. So when a good time later a redundant reply is added then not only that reply time is wasted, but my time is also wasted.
I have the same problem with replies only suggesting to add points.
I know, it is entirely my own choice to re-visit, but still...

>>> *** My long posts are not getting into forums..

I beg to differ. You may well be correct, but I suspect it was just the general reply trouble we all went through a while ago. Just wait and the replies would be there, and keep a backup copy handy just in case.

>> change my browser from Firefox..

I tend to use firefox. No problem for me.

>> ***I gave a fresh information that defers from what others gave (I used "dd" to delete where your was "dw").

fwiw: My reply mentioned dd hours earlier.

'nuff said.

I am looking forward to many more great replies from all, just less noise if you could please!

Kindest regards,
Hein.
Geoff Wild
Honored Contributor

Re: Vi Editor !!!!!

Justin,

You will find 2 camps - Those who like vi and those who don't.

Here's a good page for you full of tip and tricks for beginners"

http://www.csci.csusb.edu/dick/samples/vi.notes.html

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
dipesh_2
Regular Advisor

Re: Vi Editor !!!!!

rmueller58
Valued Contributor

Re: Vi Editor !!!!!

from within the vi editor to search for a specific string,

esc
/STRING

to search for the same string hit the "/"
again..
okcunix
Advisor

Re: Vi Editor !!!!!

lots of good references to tutorials, etc above. To answer your question, from the command mode of vi, type ":g/WORD/d"

The : puts you in ed mode,
g/WORD/d
means: globally, search for WORD, and delete the line(s) it is found on
hit the enter key.