Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Command that returns line number of the string

Tags:

linux

I have a bunch of files organized into directories..All these are text files (c/c++). I am trying to understand this code and i need to look at the declarations of many variables..How can i use find command to get the exact location( File Name with line number(s) ) using Find command in ubuntu linux?? Or is there any graphical tool for doing the same?

like image 897
nikhil Avatar asked Sep 29 '11 16:09

nikhil


People also ask

Can grep return the line number?

To Display Line Numbers with grep MatchesAppend the -n operator to any grep command to show the line numbers. We will search for Phoenix in the current directory, show two lines before and after the matches along with their line numbers.

How do you get the line number of a string in a file in Unix?

The -n argument after grep will print the line number in which the string is found in the file. using the grep command to search for strings at the start of lines and print line numbers.


1 Answers

You can do this with grep. grep -n 'search-term' *.c will give you the filename and line number where the term appears.

like image 88
arunkumar Avatar answered Sep 21 '22 04:09

arunkumar