I am using command to search for files staring from a given Directory in Unix , files ending *.sas and containing the string DB2. I then inturn want to search the resultant set of files for the Strings DSN= or DATASRC= and also print the line containing these strings. SO this is the FInd command I am using :
find '/shrproj/' -type f -name '*.sas' -exec grep -il 'DB2' {} \; 2> /dev/null | xargs egrep -Ri 'DSN=|DATASRC='
This gives me the desired ouput:
/shrproj/files/stp_code/aea_aat_stp/icrv3/bin/macro/cnct_2_eaw.sas: ,"DSN=%UPCASE(&the_database.)"
/shrproj/files/stp_code/aea_aat_stp/icrv3/bin/macro/cnct_2_eaw.sas: ,"DSN=%UPCASE(&the_database.)"
But now i also want to print the properties of the file (using the -ls option) following the above result ie the below is what i intend to achieve :
/shrproj/files/stp_code/aea_aat_stp/icrv3/bin/macro/cnct_2_eaw.sas: ,"DSN=%UPCASE(&the_database.)"
/shrproj/files/stp_code/aea_aat_stp/icrv3/bin/macro/cnct_2_eaw.sas: ,"DSN=%UPCASE(&the_database.)"
61522 19 -rwxrwsr-x 1 sas sas 18546 Jun 2 2010 /shrproj/files/stp_code/aea_aat_stp/icrv3/bin/macro/cnct_2_eaw.sas
The Properties of the file in the last line above is the same when using the find command with -ls option.
find /shrproj/files/stp_code/aea_aat_stp/icrv3/bin/macro/cnct_2_eaw.sas -ls
So how do i acheive this this for each and every file using the very first Find command i am using above ?.
Please let me know. Thanks.
Something like below should work
Which has some redundancy, since logical
-q
will exit on first match (so can not be used in conjunction with printing all matches), but shouldn't be too slow if you don't have a lot of large files withDSN=
orDATASRC=
only found near the end.Alternatively, without abusing
grep -q
too much