473,569 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.sh programming help

4 New Member
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 3014

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

Similar topics

4
2415
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 learn, object oriented, clear syntax, etc...). Can anyone assist in getting me started with learning to program and Python? Recommended reading...
2
1831
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. The paper by Norman Walsh entitled "Literate Programming in XML" seems to be a good way to do that, using a couple small namespace extensions...
12
8454
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 I really want to get back into it as I see a point with GNU/Linux. I want to get my old skills back and write something or help on some projects...
3
2468
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 a QA in an MNC in India, since I graduated in September 2003. I am working in a QA role which requires me to do some Winrunner automation, and...
26
2228
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 Internet with examples on each concept. I appreciate if any one can help me in this regard.
42
2873
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 to these programming newsgroups and asking for ready-made solutions to fairly simple programming problems. They either want someone to write code...
25
2557
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 variables public instead of using properties. Another example: passing references to forms to other classes so they can modify things (tight coupling). ...
20
2172
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 resources/references/websites so that I can find summary sheet about the confusing points of C++ and typical storage/time complexity of common data structures...
13
2024
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 programming to help me, I want to major in the computer programming field and want to know if there are any really good tutorial sites. Thanks your...
139
5855
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 guy thinking that C is a great programming language and that there is no need to program things object oriented. Many people says also that they...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.