1756496 Members
2458 Online
108848 Solutions
New Discussion юеВ

vi commands

 
SOLVED
Go to solution
DIEGO_40
Occasional Contributor

vi commands

Hi
How Can I delete a line containing a lot of specific word in a vi file? Is there an option in vi editor?

Thanks
Bye
4 REPLIES 4
Biswajit Tripathy
Honored Contributor

Re: vi commands

If you want to do this interactively while inside 'vi'
editor, I don't think so. But you could easily do this
in command like. Something like:

# cat infile | grep -v specific_word > outfile

(infile is your file name and specific_word is the specific
word and outfile is the file which would be "infile" with
all the lines containing specific_word removed).

Is this what you want?

- Biswajit
:-)
Hein van den Heuvel
Honored Contributor

Re: vi commands

You need this to be 'in place' right?
That is, same input and output file name?

In interactive vi this this easy:
/word
dd


For a script i would select grep -v as shown before, taking care not to blow away the input.

Or I would use the special perl option for this: -i = 'in place'
Example:

# cat > x
aap
noot
mies
# perl -ni -e 'print unless /noot/' x
# cat x
aap
mies
#


fwiw,
Hein.

Dwane Ballard_1
Occasional Advisor
Solution

Re: vi commands

How about g/word/d

This should delete the line, regardless of where on that line it occurs.

Dwane
DIEGO_40
Occasional Contributor

Re: vi commands

Thanks to all, I follow the Dwane command and it's work good!!

Ciao
Diego