Welcome Guest ( Log In | Register )


 
Reply to this topicStart new topic
> Grep List Filename And Line Number
NickTheGreek
post 23 Apr 2013, 11:19 PM
Post #1


Administrator
Group Icon

Group: Admin
Posts: 118238
Joined: 3-June 05
From: Athens, Greece
Member No.: 1
Zodiac Sign: I'm a leo!
Gender: I'm a m!



"Hi I am trying to search my rails directory using grep. I am looking for a specific word and I want to grep to print out the file name and line number. Is there a grep flag that will do this for me? I have been trying to use a combination of -n and -l but these are either printing out the file names with no numbers or just dumping out a lot of text to the terminal which can't be easily read.

ex:

CODE
grep -ln "search" *


Do I need to pipe it to a awk?"



I think -l is too restrictive as it suppresses the output of -n. I would suggest

-H, --with-filename
Print the filename for each match.

CODE
grep -Hn "search" *


If that gives too much output, try -o to only print the part that matches.

CODE
grep -nHo "search" *


Source : http://stackoverflow.com/questions/8105685/grep-list-filename-and-line-number



--------------------

c:\ When the going gets tough, the tough get going ...
Go to the top of the page
 
Bookmark this: Post to Del.icio.usPost to DiggPost to FacebookPost to GooglePost to SlashdotPost to StumbleUponPost to TechnoratiPost to YahooMyWeb
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 30th June 2025 - 10:47 AM
Skin and Graphics by Dan Ellis and Anubis. Hosting by Forums & More © 2005-2011.
InvisionGames - Your #1 Arcade Games Repository | AllSigs - Signatures for all | Rock Band + Guitar Hero = RockHero ! | The Remoters - Remote Assistance | FileMiners - You ask, We find