1753507 Members
5347 Online
108795 Solutions
New Discussion юеВ

vi help

 
SOLVED
Go to solution
Ted Flanders
Frequent Advisor

vi help

I am new to using vi. I need to cut some lines out of a file, save them to a new file, and delete them from the original file. I set nu......its lines 587 to 819 that I need to do this from. I tried dd to delete lines but it said it wasnt a valid vi command? It is a .txt file that I am working on, is that why it is an invalid command?
I am on a HP9000 K220 using HPUX 10.20. Any help would be appreciated.
6 REPLIES 6
Ted Flanders
Frequent Advisor

Re: vi help

PS.....this is what I thought would be the correct way of doing this.
:587,819w! /work/newfile
then go back and either dd the lines, or 232dd, neither of which worked.
Vincenzo Restuccia
Honored Contributor

Re: vi help

Kevin Wright
Honored Contributor
Solution

Re: vi help

:n,mw file
will write lines n to m to file..cp the .txt file to just file and try it again.
Steve Post
Trusted Contributor

Re: vi help

vi does not care what extension you have on the file. Unlike windows, this unix command vi, does not care what the filename is.
dd is a valid command, but maybe you were at the colon (:dd)? Vi is VERY case sensitive. For example: the J key merges lines together, while the j key jumps down one line.

To see what line you are on, hit control-G, from within the command mode. (ie not insert mode, and not with that colon at the bottom of the screen).

Here's yet another way to do this.
From unix, "vi myfile newfile"
You the h,j,k,l movement keys to go to the starting line.

"a232yy <--drop 232 lines into BUFFER a.

:n <--go to next file

"ap <--pop the 232 lines into the next file.
:w <--save newfile
:rew <--rewind back to your first file
232dd <--delete 232 lines
:wq <--get out

Buffer a? What's that you say? Oh, you have a least 26 of these little buffers.

You can run vi multiple files too.
:n next file
:rew rewind to first file

One last thing....
u - is the undo last command key.
. - is the repeat last command key.
23. - means repeat last command 23 times.
:e! - restores the file to the last time you saved it.

steve
Magdi KAMAL
Respected Contributor

Re: vi help

Hi ,

Just the following line :

:587,819w newFile.txt

Thierry Poels_1
Honored Contributor

Re: vi help

Hi,
how about:

vi yourfile
:587,819w myfile
:587,819d
:wq

regards,
Thierry
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.