Operating System - HP-UX
1830939 Members
1921 Online
110017 Solutions
New Discussion

Re: Find strings in files

 
SOLVED
Go to solution
Mauro_8
Frequent Advisor

Find strings in files

Hi,

I listed all tables of my databse to a file called tables.txt each table in one line and I want to know if these database tables are used in some source code. These source codes are under /tmp/source/dir_1, /tmp/source/dir__2 ... /tmp/source/dir_n. I used:

find /tmp/source -depth -print > find.log, to list all files under /tmp/source and it worked fine.

then I did:
egrep -i -n -f tables.txt find.log, to list the files that have one of my database tables in it.

But I do not know the table that is used because doing these commands I only know that one of the tables is present in the source code file listed but what table ? I really want to list the tables in tables.txt file that is used in one of the source code files.

Any ideas of how can I do it ?

Cheers,
Mauro
5 REPLIES 5
curt larson_1
Honored Contributor

Re: Find strings in files

a short script should work

cat find.log |
while read file
do
egrep -f tables.txt $file 1>/dev/null 2>&1
if [ $? = 0 ] ;then
print $file
fi
done
Steven E. Protter
Exalted Contributor

Re: Find strings in files

find /ias -exec grep -l '/oracle/ias/product' {} \;

Change as needed.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
curt larson_1
Honored Contributor
Solution

Re: Find strings in files

guess i should read your requirements better
> I really want to list the tables in tables.txt file that is used

how about this:

cat find.log |
while read file
do
egrep -f tables.txt $file 1>/dev/null 2>&1
if [ $? = 0 ] ;then
print "\nTables in $file:\n"
egrep -f tables.txt $file
fi
done
Elena Leontieva
Esteemed Contributor

Re: Find strings in files

Mauro,

1. You can simply go to each dir_1, dir_2 etc., i.e. cd /tmp/source/dir_1 and run a command:

egrep -f tables.txt *

2. find /tmp/source -depth -print -exec egrep -f tables.txt {} \; |more , but this will also list all the files under /tmp/source.

Elena.
vasundhara
Frequent Advisor

Re: Find strings in files

Hi,

Another way to find...

cd /tmp/source
for table in `cat tables.txt`
do
find . -type f | xargs grep $table
done

you have to give absolute path of tables.txt

Regards
VJ.