Hi friends.. I have many dirs in my working directory. Every dir have thousands of files (.jsp, .java, .xml..., etc). So I am working with an script to find every file recursively within those directories and subdirectories ending with .jsp or .java which contains inside of it, the the pattern "System.out.println", but at the same time it has to ingnore in the output those files which have same pattern, but with comment out lines: like this for example ( // System.out.println ). It has been difficult to me to ingnore those files with // System.out.println. files have tabs in some cases but in others not, I mean the format of files are diferent each others.
Here's my code.
for file in `cat /tmp/found_projects`
do
file2=`find $file \( -name "*.java" -o -name "*.jsp" \) -type f`
_file=`grep -l System.out.println $file2 | grep -v testcases`
grep System.out.println "$_file" | sed 's/^[ \t]*//' | grep "^System.out.println" >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$_file ---> Found"
else
echo "$_file ---> Not Found"
fi
done
--
The result are not the expected..
found_projects --> is the list of dirs i am using the search inside of them.
sed 's/^[ \t]*//'
--> for deleting all tabs and then check what files have lines starting with System.out.println
In conclusion, what I need is:
in conclusion is, get all the files that have the pattern System.out.println and ignore those on whose pattern is coment out, for example //System.out.println