[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

This is in AIX5.3..Need a find command to list the file and then the content of the file

Posted on 2013-02-05
3
Medium Priority
?
393 Views
Last Modified: 2013-02-05
I need a find command that runs under log directory and should list the file name and then content of the file name which I am searching for

Example:
find . -type f -print -exec grep -inH “SBL-1234” {} \; >/apps/a.txt  isnt giving the correct output

I want a find command which should search for SBL-1234  in all the logs and then list the filename and then the "SBL-1234" of the filename to a.txt only then it should go to the next log file get the log name and the "SBL-1234"  in that log
0
Comment
Question by:aixtutorial
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 38856255
try this

grep -RinH “SBL-1234” *  >/apps/a.txt
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1500 total points
ID: 38856282
cd /log/directory
for file in *.log
  do
     grep -iH “SBL-1234” $file /dev/null 2>/dev/null
  done > /apps/a.txt
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38856319
... and if you don't like the colon between the filename and the content:

cd /log/directory
for file in *.log
  do
     RESULT=$(grep -iH “SBL-1234” $file 2>/dev/null)
       if [[ ! -z $RESULT ]]; then
           echo $file $RESULT
       fi
  done > /apps/a.txt
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

650 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