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
386 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
  • 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 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now