I am using FILENAME variable of AWK to display the filename in the out put but its not getting displayed in the output. I am using Ubuntu 11.04.
Here is the code file1.sh
#!/bin/sh
for i in $@ ;
do
if [ -f "$i" ] ; then
awk 'BEGIN { printf "%s\t",FILENAME ; }
/^ *$/ { x+=1 ; }
END { ave=100*(x/NR) ; printf " %s\t%3.1f\n",x,ave; }
' "$i"
else
echo "ERROR: $i not a file." >&2
fi
done
.........Here is the file :
cat gigs.txt
http://www.cusa.berkeley.edu/~ranga
Cisco Systems, Inc
ftp://prep.ai.mit.edu/pub/gnu/
ftp://ftp.redhat.com/
Yahoo!
ranga@kanchi:/home/ranga/pub
ranga@soda:/home/ranga/docs/book/ch01.doc
I did this : ./file1.sh gigs.txt ----- In the out put I am only getting
4 36.4 but not the name of the file i.e. urls.txt however if i do echo $i then i am getting the filename........ Kindly let me know where i am wrong ?