1834150 Members
2472 Online
110064 Solutions
New Discussion

Script needed.

 
SOLVED
Go to solution
Deepak Kulkarni
Regular Advisor

Script needed.

Hi all..

I would like to write perl/shell script for the below requirement.

1) Read line by line words from a file.
2) Search that word in multiple directories
3) If it finds that word in any file, log that filename with the full path into an output file.

Thanks
DK
6 REPLIES 6
Marvin Strong
Honored Contributor

Re: Script needed.


for word in `cat file`
do
grep $word /list/* /of/dirs/* | awk -F: '{print $1}' > logfile
done



Marvin Strong
Honored Contributor

Re: Script needed.

oops need >> or to redirect after the done.


for word in `cat file`
do
grep $word /list/* /of/dirs/* | awk -F: '{print $1}' >> logfile
done
Victor Fridyev
Honored Contributor
Solution

Re: Script needed.

#!/bin/sh

cat file | while read string; do
for word in $string; do
find dir1 dir2 dir3 -exec grep -l $word {} \;
done #for
done > logfile
Entities are not to be multiplied beyond necessity - RTFM
spex
Honored Contributor

Re: Script needed.

Hi DK,

For a different approach...

#!/usr/bin/sh
F_IN=/your/file
F_OUT=/your/results
tr -s "[:space:]" "[\n*]" < ${F_IN} > /tmp/wl.${$}
find / -print | grep -F -f /tmp/wl.${$} > ${F_OUT}
rm -f /tmp/wl.${$}
exit

PCS
Arturo Galbiati
Esteemed Contributor

Re: Script needed.

Hi,
a one-line command:

grep -l -f file /dir1/dir1/* /dir2/dir/*

This command print only the fullpatchname of teh file where the search string conatined into file are found.

this run on my HP-UX11i.

HTH,
Art
Deepak Kulkarni
Regular Advisor

Re: Script needed.

Hi Everybody...

Thanks to everyone...

Cheers
DK