Operating System - HP-UX
1832978 Members
2813 Online
110048 Solutions
New Discussion

Re: Searching for a pattern in vi starting from the last line

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Searching for a pattern in vi starting from the last line

Hi,

I want to search for a pattern in vi editor which contains large number of entries.
I know only how to search forward by opening the file in vi and executing /pattern.

But do not know how to search a pattern starting from the bottom of the page and going back ward searching line by line.

Can someone please let me know ?

Thanks,
Shiv
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Searching for a pattern in vi starting from the last line

Hi Shiv:

Instead of a slash ('/') to scan forwards, use a question-mark ('?').

See the manpages for 'vi'.

Regards!

...JRF...
Court Campbell
Honored Contributor

Re: Searching for a pattern in vi starting from the last line

Hit shift+g to go to the end of the file. Then run the search. Then use shift+n to go backward in the list.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Ninad_1
Honored Contributor

Re: Searching for a pattern in vi starting from the last line

Hi,

/ sets the direction as forward search and ? sets the direction as backwards search.
Then to continue and search the next pattern in the direction that you have set, simply press/type n

Regards,
Ninad
Nitin Kumar Gupta
Trusted Contributor

Re: Searching for a pattern in vi starting from the last line

Go to a perticular line,

esc + : + line number.

So, your target is last line

esc + : + $, you will reach at last line.

Write your pattern with /

+ n will move the cursor backward.

Rgds
-NKG-
Dennis Handly
Acclaimed Contributor

Re: Searching for a pattern in vi starting from the last line

>Nitin: Go to a particular line

You don't need to type the colon if you type: number G
To go to the end, just type G.