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
388 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

825 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