Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

UNIX grep command question

On a Solaris10 server I am at the directory:

#/usr/mydir/
#

I am looking for files in the directory that has the string "abcd" in the content of the file.
# cat * | grep abcd
The above command gives the lines of those files matching the string. How do I get the actual file names in which the string occurs?
0
toooki
Asked:
toooki
2 Solutions
 
ozoCommented:
grep abcd *
0
 
ozoCommented:
or
grep -l abcd *
0
 
omarfaridCommented:
if you have a lot of files and if you want to ignore case (e.g. file contains Abcd) then tey

find . | xargs grep -i abcd
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
ozoCommented:
find will also find files in subdirectories, unless you restrict it
0
 
upanwarCommented:
Here you will find lots of example for your need.

http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/
0
 
TomuniqueCommented:
what you're asking for is the -l (lower case L ) parameter

also, please see the manual pages for grep
 use the "man grep" command, or, google "unix man pages" and find several sites on the internet

Tom
0
 
toookiAuthor Commented:
Ok thank you all. I could get my work done.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now