![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix | mailsukumar | Shell Programming and Scripting | 0 | 05-26-2008 05:12 AM |
| UNIX newbie NEWBIE question! | Hanamachi | UNIX for Dummies Questions & Answers | 3 | 09-14-2006 07:23 AM |
| hello unix newbie | Combat Form | UNIX for Dummies Questions & Answers | 1 | 05-01-2004 05:16 AM |
| Unix Newbie | u6ik | UNIX Desktop for Dummies Questions & Answers | 7 | 03-19-2004 08:11 AM |
| am a unix newbie | mysticalpotato | UNIX for Dummies Questions & Answers | 12 | 09-15-2003 09:05 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Newbie to HP Unix
Hi
Im a newbie to unix having been a windows guy, yes I know a swear word on here ? but part of my new job is to be trained up on Unix. On the course we were set a task to read a file that has dates times codes etc, a log file. see below as an example 2007/02/19 00:00:06: Information: Switch SDT for out stream 510 2007/02/19 01:00:00: Information: Switch SDT for out stream 510 2007/02/19 01:59:00: Information: Switch SDT for out stream 510 My task is to look through this file and display the output for a start time and end time ? so eg start time is 01:00:00 and end time 05:00:00 My question is how do you do this and what if the first time is 01:01:00, how do you search for this ? My code so far is this #! /bin/sh rm temp.log clear echo "Please enter word to search for : " read searchstring echo "Please enter outstream to search for : " read outstream echo "Switch or Build : " read switchorread echo "Please enter search date : (yyyy/mm/dd) " read searchdate echo "Please enter start time : (hh:mm:ss) " read starttime echo "Please enter end time : (hh:mm:ss) " read endtime echo $searchstring $outstream $switchorread $searchdate $starttime $endtime cat /users/duncan/shepd/xsg.log|grep -i $searchstring|grep $outstream|grep -i $switchorread|grep $searchdate >temp.log The expamle at the top is the out put for temp.log How can I search temp.log for a set time and end time and out put this this to screen or a file ? Any help in point me to the right commands, rather then telling me what code I should write, Id appricate it thanks |
| Forum Sponsor | ||
|
|
|
||||
|
A version a little more concise of Perderabo script :
Code:
#!/usr/bin/ksh
timetosecs()
{
integer time h m s
echo $1 | IFS=: read h m s
echo $((h*3600+m*60+s))
}
read searchstring?"Please enter word to search for : "
read outstream?"Please enter outstream to search for : "
read switchorread?"Switch or Build : "
read searchdate?"Please enter search date : (yyyy/mm/dd) "
read starttime?"Please enter start time : (hh:mm:ss) "
read endtime?"Please enter end time : (hh:mm:ss) "
startsecs=$(timetosecs $starttime)
endsecs=$(timetosecs $endtime)
exec < $outstream
while read date time rest ; do
[[ $date != $searchdate ]] && continue
secs=$(timetosecs $time)
(( secs < startsecs && secs > endsecs )) && continue
echo $date $time $rest
done
Jean-Pierre~ |
|
||||
|
Quote:
You need: h=${h#0} m=${m#0} s=${s#0} I also think that limiting the scope of h, m, and s is a good idea, but using global variables causes no harm in this script as it currently exists. |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|