473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

.sh programming help

I'm only new to learning shell programming and we have this current task to create a .sh program (basic shell only) that can output a web access statistics report of accesses for each month in a year or total number of accesses in a particular month in a year selected by the user.

So what we have is a .txt file containing lines like the following:
66.196.90.230 - - [01/Mar/2004:01:28:59 +1000] "GET /robots.txt HTTP/1.0" 404 282

My current problem is I cannot figure out how to break the text into substrings based on field separators of "/", and only to use the month(Mar) or year(2004). Also need a counter which is updated according to the substrings found in the input data.

This is what I have so far, and it doesn't function like I want:
# process all arguments (i.e. loop while $1 is present)
while [ -n "$1" ] ; do
# echo "Arg is $1"

case $1 in
-h*|-H*) echo "help msg1" ; echo "help msg2" ;
shift ;;

[12][0-9][0-9][0-9]) the_year=$1 ;
shift ;;

Jan*|jan*|JAN*) the_month="Jan" ; shift ;;
Feb*|feb*|FEB*) the_month="Feb" ; shift ;;
Mar*|mar*|MAR*) the_month="Mar" ; shift ;;
Apr*|apr*|APR*) the_month="Apr" ; shift ;;
May*|may*|MAY*) the_month="May" ; shift ;;
Jun*|jun*|JUN*) the_month="Jun" ; shift ;;
Jul*|jul*|JUL*) the_month="Jul" ; shift ;;
Aug*|aug*|AUG*) the_month="Aug" ; shift ;;
Sep*|sep*|SEP*) the_month="Sep" ; shift ;;
Oct*|oct*|OCT*) the_month="Oct" ; shift ;;
Nov*|nov*|NOV*) the_month="Nov" ; shift ;;
Dec*|dec*|DEC*) the_month="Dec" ; shift ;;

*) echo "? unrecognised input: $1" ;
shift ;;
esac
done

echo "Got month: $the_month"
echo "Got year: $the_year"

oldIFS="$IFS"
count=0
IFS="/"; while read file
do
set $file
IFS=":"
set $1

if [ "$3" = "$the_year" ]
then
echo $file
count=`expr $count + 1`
else
if [ "$2" = "$the_month" ]
then
echo $file
count=`expr $count + 1`
fi
fi
done < my_sample_log2.txt
echo $count
IFS=$oldIFS
I think its the two changes of the IFS, but I cant find anything in my notes on how else to do this. Thanks for any help.
Apr 6 '06 #1
0 3003

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark | last post by:
Hello. I am new to programming and Python and was wondering if someone could help get me started. I picked Python to start learning to prgram because of some things I have read about it (easy to...
2
by: Mike Maxwell | last post by:
(apologies if this is not the right place to ask--suggestions on a more appropriate venue welcome!) I would like to do some literate programming-type writing, probably using the DocBook format. ...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
3
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as...
26
by: Kanthi Kiran Narisetti | last post by:
Hi ALL, I am new to C and programming . I need suggestions for the IDE to be used as a begginer and should I start on Windows or Linux ?? I am also looking for resources for C programming on...
42
by: Kevin Spencer | last post by:
Is it just me, or am I really observing a trend away from analysis and probem-solving amongst programmers? Let me be more specific: It seems that every day, in greater numbers, people are coming...
25
by: Dave | last post by:
I want to spend two minutes on my soapbox. I love C#. I am so productive in it it's ridiculous. But it's so easy to write code that uses poor design principles. Example: just making...
20
by: Mike | last post by:
Hi all, I am cramming for an technical interview about C++ and programming... I believe there will be problems on data-structures and algorithms... could anybody recommend some online...
13
by: 1jasong | last post by:
Hello I am new to programming and want to know what is a good free compiler is. I am asking this because there are so many of them and I just want to start programming also a good website for...
139
by: Joe Mayo | last post by:
I think I become more and more alone... Everybody tells me that C++ is better, because once a project becomes very large, I should be happy that it has been written in C++ and not C. I'm the only...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.