grazinggoat
Programmer
Hello,
I want to search a directory for a pattern and if its found with a comment to ignore the file
but i want the return code or value. the reason is after checking for the pattern
if its not a commented line i want to grab the lines from the file if its commented I don't want
to know about the file at all.
So lets say file A is in DIR looks like this:
bird
dog
cat
and file B is
#bird
dog
cat
Then good I want to know bird was found in DIR
but if only file B in DIR has #bird I don't want to know
it was there when i data mine for bird.
I want to only know that my search for bird was found in DIR if file A or any other file contain uncommented bird.
doing grep bird DIR/* |grep -v ^# returns 0 because it still finds bird even though it will suppress it.
same with the egrep I am using egrep -h "^[^#].*$h" DIR/*
here is a watered down version what I am doing
for X in `cat list`
do
#See if pattern is in directory to proceed.
FOUND=$( egrep -h "^[^#].*$X" DIR/* )
if [[ $? = 0 ]]
then
#Found X now check each file and print X to template file.
echo "building template"
touch template.txt
for F in `cat flist`
do
grep -h "$X" DIR/$F | grep -v "^#"
if [[ $? = 0 ]]
then
echo "$X Found in DIR/$F
grep $X DIR/$F >> template.txt
else
echo "not found"
continue;
fi
done
else
echo "Not found"
continue;
fi
done
I want to search a directory for a pattern and if its found with a comment to ignore the file
but i want the return code or value. the reason is after checking for the pattern
if its not a commented line i want to grab the lines from the file if its commented I don't want
to know about the file at all.
So lets say file A is in DIR looks like this:
bird
dog
cat
and file B is
#bird
dog
cat
Then good I want to know bird was found in DIR
but if only file B in DIR has #bird I don't want to know
it was there when i data mine for bird.
I want to only know that my search for bird was found in DIR if file A or any other file contain uncommented bird.
doing grep bird DIR/* |grep -v ^# returns 0 because it still finds bird even though it will suppress it.
same with the egrep I am using egrep -h "^[^#].*$h" DIR/*
here is a watered down version what I am doing
for X in `cat list`
do
#See if pattern is in directory to proceed.
FOUND=$( egrep -h "^[^#].*$X" DIR/* )
if [[ $? = 0 ]]
then
#Found X now check each file and print X to template file.
echo "building template"
touch template.txt
for F in `cat flist`
do
grep -h "$X" DIR/$F | grep -v "^#"
if [[ $? = 0 ]]
then
echo "$X Found in DIR/$F
grep $X DIR/$F >> template.txt
else
echo "not found"
continue;
fi
done
else
echo "Not found"
continue;
fi
done