This is an extract from a script that i am trying to run.
for tim in "2005:00:" "2005:01:" "2005:02:" "2005:03:" "2005:04:" "2005:05:"; do
FormString="$tim"
echo "grep '$FormString' access.10Aug-1201AM"
count=\`grep "$FormString" access.10Aug-1201AM | wc -l\`
echo " Time : $tim Count : $count"
done
but whn i execute this i get an error
grep '2005:00:' access.10Aug-1201AM
grep: can't open access.10Aug-1201AM
0
.
.
but if i am executing this command manually
grep '2005:00:' access.10Aug-1201AM
i get a count
why is this not working whn executed thru the script??
Any inputs??
Thanks in advance..
Works fine for me....
$ cat > hamsasal.sh
for tim in "2005:00:" "2005:01:" "2005:02:" "2005:03:" "2005:04:" "2005:05:"; do
FormString="$tim"
echo "grep '$FormString' access.10Aug-1201AM"
count=`grep "$FormString" access.10Aug-1201AM | wc -l`
echo " Time : $tim Count : $count"
done
$ vi access.10Aug-1201AM
$ chmod +x ./hamsasal.sh
$ ./hamsasal.sh
grep '2005:00:' access.10Aug-1201AM
Time : 2005:00: Count : 1
grep '2005:01:' access.10Aug-1201AM
Time : 2005:01: Count : 1
grep '2005:02:' access.10Aug-1201AM
Time : 2005:02: Count : 0
grep '2005:03:' access.10Aug-1201AM
Time : 2005:03: Count : 0
grep '2005:04:' access.10Aug-1201AM
Time : 2005:04: Count : 0
grep '2005:05:' access.10Aug-1201AM
Time : 2005:05: Count : 0
Is your script located in the same directory as the files you're processing? If not, then it won't be able to open them as you are not specifying the full path to the file.
Either specify the full path, or add a line before the for loop cd'ing into the appropriate directory.
Cheers
ZB