[prog] Grep
Dana Jansens
danakj at orodu.net
Mon May 19 14:33:46 UTC 2008
Hi Anshika,
On Mon, May 19, 2008 at 10:03 AM, anshika kalra <kalra.anshika at gmail.com> wrote:
> Hi,
>
> I was trying to get the name of file from directory using grep.
> grep <filename> <directory name>
> But no result was displayed.Since linux treats directories also as files
> then why is this happening?
Grep expects to be given a file to read input from. If you want to
grep on a list of files, I would do something like "ls <directory> |
grep <filename>"
> Could someone also tell why
> grep '<word1>' '<word2>' <filename> displays an error.I only know that
> placing these words in a file and then using fgrep or grep -f gives result.
> Is there any other way.
Only the first argument is treated as a search term. You can pipe one
grep through another though to perform an AND operation, like "grep
<word1> <filename> | grep <word2>".
Hope that helps :)
Dana
More information about the Programming
mailing list