?
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
?
397 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 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