My goal is to find files contain the "signal 11" string in a specific directory. I need the file details followed by the string.
I wrote a script to test out and play with Shell command since it's my first time to write a Shell script.
Let me cut the story short...
this command line: if [ 'grep -i "signal 11" $fil' -ne "" ]
returns nothing, but actually in reality, I have couple files contains "signal 11" string.
My question is, why does the script not return a list of files which contains "signal 11"?
Is there anything wrong with my script that you can see?
Thanks in advance!
==========================================
#!/bin/sh
#
RESULT=/disk2/app/applmgr/appltop/cssm_custom/11.5.0/out/W2.out
if [ -f /disk2/app/applmgr/appltop/cssm_custom/11.5.0/out/W2.out ]
then
rm $RESULT
fi
#List all modified files more then 7 days in the Directory
for fil in `find /disk2/app/applmgr/comntop/admin/log/ARDEV_arebdd -type f -mtime +7`
do
#Check if the file contains "signal 11"
#If Yes, print out the file name to the output file.
if [ 'grep -i "signal 11" $fil' -ne "" ]
then
echo "fil = $fil" >> $RESULT
fi
done
if grep -ic "signal 11" $fil
then
echo "fil = $fil" >> $RESULT
fi
if your grep supports -l (no need to use if/else )
grep -l pattern $fil >> out
another way
awk '/pattern/{print FILENAME;exit}' $file >> out