Home » Infrastructure » Unix » Finding the file name
Finding the file name [message #223433] Thu, 08 March 2007 21:31 Go to next message
kmkumar24
Messages: 69
Registered: January 2007
Location: Singapore
Member
Hi All,

Kindly tell me how to find the file name with the contents only in UNIX using grep or anything.

Thanks in advance

Magesh

Re: Finding the file name [message #223447 is a reply to message #223433] Thu, 08 March 2007 23:58 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
"grep -l" will list the file names. For more options, do a "man grep".
Re: Finding the file name [message #226114 is a reply to message #223433] Thu, 22 March 2007 10:33 Go to previous messageGo to next message
strazaan
Messages: 1
Registered: March 2007
Junior Member
Try the following trick:

find . -type f -exec grep your_string {} /dev/null \;

In this case You have 2 files: {} and /dev/null, so the name of the file will be displayed by grep.
Re: Finding the file name [message #226459 is a reply to message #226114] Fri, 23 March 2007 17:37 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
grep -l AAA *.txt


or multiple patterns
egrep -l "AAA|BBB" *.txt


Previous Topic: Difference between init 0 and init 5 -solaris 8.
Next Topic: How to write a shell script to execute a procedure with in and out parameter
Goto Forum:
  


Current Time: Thu Mar 28 12:54:09 CDT 2024