Results 1 to 7 of 7
Hi,
Im currently trying to make a script that can read through every line of a text file and compare a value to a day given by the user and ...
- 04-09-2009 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 3
Reading every line and counting
Hi,
Im currently trying to make a script that can read through every line of a text file and compare a value to a day given by the user and if it matches it will incease a variable by 1 and then move onto the next line and do the same,
the text file is layed out like this,
ipaddress day month daydate time timezone year
I have managed to get this far
And now im not sure where to go, ive tried using a it statement but i got completely lost and ive also tried the awk thing but i don't know enough to figure it out.Code:echo Please enter a day e.g. Mon read DAY NUMBER=0
Can anyone point me in the right direction.
Thanks
- 04-09-2009 #2
Check out the grep command UNIX man pages : grep ()
Linux User #453176
- 04-09-2009 #3Just Joined!
- Join Date
- Apr 2009
- Posts
- 3
hi, thanks for the quick reply,
The grep command works great, i have managed to count how many lines contain e.g. Mon, can it also be used to find if the time in the line is between a certain time range e.g. between 3pm and 5pm.
- 04-10-2009 #4
I think this might work out
(grep 3) && (grep 5 )&& echo "this line contains both 3 and 5"
- 04-10-2009 #5Just Joined!
- Join Date
- Apr 2009
- Posts
- 3
hi,
this is an example of one of the lines
45.345.345.345 Mon May 04 12:03:26 GMT 2007
is it possible to pull the date and time from the string and then find out what the scecific date and hour it is e.g. 2nd and the hour eg 06, and the we can probably us a if statement or something to compare if the hour matches the hour in the string.
i am thinking something like awk would be able to do it as you can use $0 $1 $2 etc but not sure how you would get it to split the time into hour minute and seconds. Im guessing ther has to be a if statement in there as well.
thanks
- 04-14-2009 #6
If you use awk to extract the time you can then use a substring extraction to spit the hour/min/seconds. To do a substring extraction use:
You will also find it useful to use a pipe to send the output of your awk into the substring extractor. BASH Programming - Introduction HOW-TO: PipesCode:${string:start_position:length}Linux User #453176
- 04-14-2009 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458


Reply With Quote
