home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 30.15 Useful Global Commands (with Pattern Matches) Chapter 30
vi Tips and Tricks
Next: 30.17 Capitalizing Every Word on a Line
 

30.16 Counting Occurrences; Stopping Search Wraps

Want to see how many times you used the word very in a file? There are a couple of easy ways.

First, tell vi to stop searching when you get to the end of the file. Type the command :set nowrapscan or put it in your .exrc file ( 4.9 ) .

  1. Move to the top of the file with the 1G command. Search for the first very with the command /very (HINT: using the word-limiting regular expression /\<very\> ( 26.4 ) instead will keep you from matching words like every ). To find the next very , type the n (next) command.

    When vi says Address search hit BOTTOM without matching pattern , you've found all of the words.

  2. Use the command:

    
    
    :g/very/p
    
    

    The matching lines will scroll down your screen.

To find the line numbers, too, type :set number before your searches.

- JP


Previous: 30.15 Useful Global Commands (with Pattern Matches) UNIX Power Tools Next: 30.17 Capitalizing Every Word on a Line
30.15 Useful Global Commands (with Pattern Matches) Book Index 30.17 Capitalizing Every Word on a Line

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System