Computing.Net > Forums > Unix > Unix VI help

Unix VI help

Reply to Message Icon

Original Message
Name: Peter888
Date: September 24, 2003 at 06:49:31 Pacific
Subject: Unix VI help
OS: UNIX
CPU/Ram: 4
Comment:

Hi everybody,
Does anyone knows how to do this vi trick ?

For example:
------------
I have a text file containing 100 lines of the following characters:
aaaaa
bbbbb
ccccc
ddddd
eeeee
---
---
---
etc

Question:
---------
If I open this text file using vi and I'd like to insert a word 'test' (for example) at the end of each line. Is there a one line vi command that can perform this task at one go, considering I've so many lines (100 lines) ?

I do know that I can use '.' to repeat the last executed command, but for 100 lines ?

Please kindly help.
Thanks a lot.


Report Offensive Message For Removal

Response Number 1
Name: Nails
Date: September 24, 2003 at 08:43:35 Pacific
Subject: Unix VI help
Reply: (edit)

Hi:

while in vi, press the colon, :

and type:

g/$/s//test/g

Regards,

Nails


Report Offensive Follow Up For Removal

Response Number 2
Name: masayako
Date: September 24, 2003 at 15:31:57 Pacific
Subject: Unix VI help
Reply: (edit)

In this command,

What is the $ (dollar sign) meant??


Report Offensive Follow Up For Removal

Response Number 3
Name: Peter888
Date: September 25, 2003 at 02:03:13 Pacific
Subject: Unix VI help
Reply: (edit)

Thanks a lot Nails for the tips. I have yet to try it out, but I'm confident that it will solve my puzzle.

By the way, doesn't it need to specify how many time the task should be perform ? Let's say if I want to add that word (test) for the first top 50 lines only. How could that be done ?

- Peter


Report Offensive Follow Up For Removal

Response Number 4
Name: WilliamRobertson
Date: September 25, 2003 at 07:24:01 Pacific
Subject: Unix VI help
Reply: (edit)

:1,50s/$/test

meaning from lines 1 to 50, substitute end of line with the word "test". (vi doesn't actually remove the linefeed, "$" just refers to a logical end-of-line.)


Report Offensive Follow Up For Removal

Response Number 5
Name: Peter888
Date: September 25, 2003 at 10:55:04 Pacific
Subject: Unix VI help
Reply: (edit)

Thanks a lot William.
Much appreciated for your help.

Have a nice day.

- Peter


Report Offensive Follow Up For Removal


Response Number 6
Name: Peter888
Date: September 25, 2003 at 11:02:06 Pacific
Subject: Unix VI help
Reply: (edit)

Hi,

Does anyone knows where to dig out in more details and of course with examples (if possible) on how to use this vi additional commands / variables ? Any good online reference or website ?

Please kindly help.
Thanks.

- Peter


Report Offensive Follow Up For Removal

Response Number 7
Name: Nails
Date: September 25, 2003 at 13:41:31 Pacific
Subject: Unix VI help
Reply: (edit)

Peter:

The vi book I like best is:

Learning the vi Editor by Linda Lamb and Arnold Robbins published by O'Reilly.

There's a ton of vi links on the web. I like this document from Berkeley:

http://www.cs.berkeley.edu/~janp/Help/onlinedocs.html#vi

Regards,

Nails


Report Offensive Follow Up For Removal

Response Number 8
Name: WilliamRobertson
Date: September 26, 2003 at 15:41:43 Pacific
Subject: Unix VI help
Reply: (edit)

I'll second that vote for the O'Reilly book.

Notice that vi is called "vi" or sometimes "Vi" but not "VI". Also there seems to be an odd tradition in the documentation of claiming that it is pronounced "Vee-Eye", when in fact everyone has always called it "Vye". Rather like pronouncing ".wav" as "Dot Wave". Strange...


Report Offensive Follow Up For Removal

Response Number 9
Name: Sean Miller
Date: September 26, 2003 at 22:55:37 Pacific
Subject: Unix VI help
Reply: (edit)

Before I somehow managed to mislay it, the book I swore by was "Unix in a Nutshell", also by O'Reilly.

It doesn't teach anything, but is an excellent reference manual of everything Unix... from vi to sed to awk to ksh or csh to pattern matching... just about everything you need to know about Unix is in there somewhere, without too much waffle.

Sean


Report Offensive Follow Up For Removal

Response Number 10
Name: Peter
Date: October 6, 2003 at 09:33:22 Pacific
Subject: Unix VI help
Reply: (edit)

Hi guys,

Sorry for the late reply.
I just wanted to say thanks so ... so much for helping me and for those extra information. Much appreciated.

Keep up the good work guys!!!

- Peter


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Unix VI help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software