?
Solved

Searching all files in a directory for a specfic word

Posted on 2012-08-23
7
Medium Priority
?
311 Views
Last Modified: 2012-10-13
I want to read all files within the log directory to locate the word BASH or bash and present it to my screen.

Would I simply ?

cd logs
grep -i bash
0
Comment
Question by:Nicenchrisp
  • 3
  • 3
7 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 600 total points
ID: 38324260
you should specify the files or file pattern.  Use * for all
    grep -i bash *
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 38324268
You could use:
grep -H -r -i bash /logs/* (or /var/logs/*, where ever the dir is.
This shows the filenames containging the word, searches also any subdirectories and ignores the upper/lower case.
And if you want to see the lines where the word is found, leave out the -H.
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 38324272
Darn, still typing too slow ;)
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 

Author Comment

by:Nicenchrisp
ID: 38324628
this is a good answer

grep -H -r -i bash /logs/*


If I wanted it to be placed in a file can I safley assume....

grep -H -r -i bash /logs/* > /tmp/output
0
 

Author Comment

by:Nicenchrisp
ID: 38324675
I have to use ksh for this also !
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 38324756
grep -H -r -i bash /logs/* > /tmp/output
You can safely assume that :)

This should run in ksh as well I assume. Let me see if I have a ksh laying around somewhere.........
0
 

Author Comment

by:Nicenchrisp
ID: 38332590
The grep -H -r does not work on ksh for me ?  Doesn't like either -H or -r
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question