Wednesday, March 25, 2015

How to open file and go to the specific line or text string in Linux

P
This tutorial could resolve a problem that you want to edit a text file with the line number goes up to a hundred. Now you don't have to scroll down and wait until you're at the line need to be changed.
Please note that, this tutorial I am going to show you just works with vi/vim command, so your PC must be installed either of them.

About usage, vi and vim has the same way to use. Now I will show you how to do this

vi +SearchString fileName

Or

vi +LineNumber fileName

Others ways

vi +/SearchString fileName
vi +/LineNumber fileName
vim +/LineNumber fileName

Sample

In case you want to open Hello.java at line 90
vi +90 Hello.java

In case you want to open Hello.java at function say()
vim +/"say()" Hello.java

References

No comments:

Post a Comment