Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Nov 092010
 

Only show filenames in grep command

Answer:

Sometimes you want the grep command only return the filenames that matched a pattern, you can try the following:

# grep -r -l "foo" .

The key is the -l option.

  2 Responses to “Only show filenames in grep command”

  1. i need only the output answers .. not serial number =m12345. i need only the output m12345 .how to do ?

  2. @balaji

    I am not sure what you want exactly, maybe you want the part after the "=" ?

    cat test.txt | cut -d '=' -f2

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>