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

Technology Partners: 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

Suggested Solutions

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

733 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