Using grep in find

Hi,
On AIX,
We have several moveplan.xml files in different folders.
I run:

find /u0/appl_top/ -name moveplan.xml -exec grep -i Passphrase {} \;

And it returns

<name>Custom Identity Keystore Passphrase File</name>
                        <name>Custom Trust Keystore Passphrase File</name>
                        <name>Custom Identity Private Key Passphrase File</name>
                        <name>Custom Identity Keystore Passphrase File</name>
                        <name>Custom Trust Keystore Passphrase File</name>
                        <name>Custom Identity Private Key Passphrase File</name>
                        <name>Custom Identity Keystore Passphrase File</name>
                        <name>Custom Trust Keystore Passphrase File</name>
                        <name>Custom Identity Private Key Passphrase File</name>

Is there any option to have complete path where the files are situated?
Thanks.

Not sure if this helps... but maybe it will, if you try to add:

find "$(pwd)"

YMMV, let us know if it works for you.

Hello big123456,

IMHO I think you are looking for grep -l option, since it will only print Filenames which have that specific text in them, try something like:

find /tmp/ -type f -exec grep -l "Give your text here..." {} \+ 2>/dev/null

In my tested case output was as follows.

/tmp/test_singh
/tmp/test1234

In above code change /tmp/ with your actual/complete path details and it should provide it in your output. Also I have kept 2>/dev/null for removing Errors its up to you in case you want to see errors on screen.

From man page of grep:

Thanks,
R. Singh

1 Like

Check out GNU specific grep option

find /u0/appl_top/ -name moveplan.xml -exec grep -H -i Passphrase {} \;

Or without GNU grep option

find  /u0/appl_top/ -type f -name '*.txt' -exec grep -i Passphrase {} /dev/null \;

Hope that helps
Regards
Peasant.

Thanks.