Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using vi to display a line number

Status
Not open for further replies.

noiz

IS-IT--Management
Apr 19, 2001
17
US
Hi

I'm trying to find a way to use vi to display the line number of a file of the first occurance of a word in a file.
I guess i could use awk but was wondering if their was another way to do it in vi.

tks

zion
<><
=-)
 
You can do that in two steps

/word
G

Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi

For setting this open a file .exrc in your home directory
and enter the following line

set nu

and save the file

You shd be able to get the line numbers when u open vi the next time on

Regards

D..
 
if all you want is the line number of the first instance of a word in a file, you could skip vi and try:

grep -n word file | head -1
 

/word (to find the word)
Ctrl/g (will display line number at bottom of screen)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top