I am writing a script that calls an awk script and takes 2 arguments:
argument #1 is a directory
argument #2 is a filter
The awk script performs some statistical operations. The input file(s) are gzip-ed files called "access_log.gz". In order to get a "per file" output I use a "while-loop" in which I call my awk-script.
To implement an element of sorting, my idea was to "grep" for the searchword.
In order I do a "gzcat" piped into the "grep" piped into the awk-script.
For some strange reason when I manually execute my command line (HP-UX-11.00) I get the desired result, but when I call the exact same line within my shell script I get no filtering (grep seems to fail completely).
To get an idea what I am talking about, some lines of code from my script:
# check for arguments (1st argument must be a valid directory)
if [ $# -eq 0 ] || [ ! -d $1 ]; then
echo "ERROR."; exit
fi
myTargetDir=$1
# check for 2nd argument (will be used as search pattern)
if [ $2 ]; then
mySearchPattern="| grep $2 "
myCustomVars="-v mySuffix=$2 "
else
mySearchPattern=""
myCustomVars=""
fi
# start looking in myTargetDir and find all instances of mySearchFile
cd $myTargetDir
find . -name $mySearchFile | while read myFileName
do
gzcat $myFileName $mySearchPattern| awk $myCustomVars-v myFileName=$myFileName -f $myScriptDir$myScriptName
done 2>> $myLogfileDir$myLogfileName
I have added an extra line with echo "..." duplicating the red line of code and copy & pasted this command into my command line - that works just finde ... I don't see my error. Please help!
argument #1 is a directory
argument #2 is a filter
The awk script performs some statistical operations. The input file(s) are gzip-ed files called "access_log.gz". In order to get a "per file" output I use a "while-loop" in which I call my awk-script.
To implement an element of sorting, my idea was to "grep" for the searchword.
In order I do a "gzcat" piped into the "grep" piped into the awk-script.
For some strange reason when I manually execute my command line (HP-UX-11.00) I get the desired result, but when I call the exact same line within my shell script I get no filtering (grep seems to fail completely).
To get an idea what I am talking about, some lines of code from my script:
# check for arguments (1st argument must be a valid directory)
if [ $# -eq 0 ] || [ ! -d $1 ]; then
echo "ERROR."; exit
fi
myTargetDir=$1
# check for 2nd argument (will be used as search pattern)
if [ $2 ]; then
mySearchPattern="| grep $2 "
myCustomVars="-v mySuffix=$2 "
else
mySearchPattern=""
myCustomVars=""
fi
# start looking in myTargetDir and find all instances of mySearchFile
cd $myTargetDir
find . -name $mySearchFile | while read myFileName
do
gzcat $myFileName $mySearchPattern| awk $myCustomVars-v myFileName=$myFileName -f $myScriptDir$myScriptName
done 2>> $myLogfileDir$myLogfileName
I have added an extra line with echo "..." duplicating the red line of code and copy & pasted this command into my command line - that works just finde ... I don't see my error. Please help!