- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: orders
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 08:28 AM
04-06-2004 08:28 AM
orders
I have plain text file which has business orders with time stamp. I want to grep orders for every five minutes starting from 12PM-4PM. Time format is like HH:MM:SS.Please help.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 09:55 AM
04-06-2004 09:55 AM
Re: orders
awk -v hour=$hour -v min-$min '
/[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}/ {
for ( i=1,i<=NF;i++ ) {
if ( $i ~ /[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}/ ) date = $i;
}
split(date,a,":");
if ( hour == a[1] ) {
m1=sprintf("%d",a[2]/5;
m2=sprintf("%d",a[2]/5;
if ( m1 == m2 ) print $0;
}}'
then it is pretty easy to loop through hours and minutes
ehour=5
hour=12
min=0
while (( $hour < ehour ))
do
while (( $min < 60 ))
do
#do the above script
min=$(( $min + 5 ))
done
hour=$(( $hour + 1 ))
if (( $hour > 12 )) ;then
hour=$(( $hour - 12 ))
done
you'll have to decide how you handle AM/PM issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 10:08 AM
04-06-2004 10:08 AM
Re: orders
m1=sprintf("%d",a[2]/5;
m2=sprintf("%d",a[2]/5;
one should be min, as in:
m1=sprintf("%d",a[2]/5;
m2=sprintf("%d",min/5;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 10:22 AM
04-06-2004 10:22 AM
Re: orders
Not really sure what you want...
if you want to get all lines from a text file where the hours are 12,01,02,03,04 PM with regular minutes 00 to 59 ... :
grep '[12,01,02,03,04]:[0-5][0-9]:[0-5][0-9]' textfile
For the 5 minutes interval, the regular expression can be :
[05,10,15,20,25,30,35,40,45,50,55]
Hope that helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 03:11 PM
04-06-2004 03:11 PM
Re: orders
Like is that text file already sorted by time? What about am-pm, did you want to grep for a orders in a 5 minute block where that block in perhpas indicated in a variable?
Here is a perl (or awk) solution to group an assumed to be pre-sorted file in labeled 5-minute intervals.
usage: perl -n time-groups.pl < textfile
Where time-groups.pl contains:
if (/(12|01|02|03)(:\d+:)(\d+)/) {
$range = sprintf("%s%s%02d",$1,$2,5*int($3/5));
print "\n-- $range --\n" unless ($headers{$range}++);
print;
}
find line with 12,01,02 or 03 (remeber in $1) followed be a decimal between colons (remember in $2) followed by a decimal (in $3).
Calculate group header as the first 2 found strings for HR:MM: and 'floor' the seconds by fives. ( divide by factor, int, re-mutiply by factor).
Print header with group range unless already printed as indicated by a counter in hash array.
Print line (if is matched the range)
Sample input:
12:00:04 aap
02:09:40 een noot
02:09:41 twee noot
02:09:42 drie noot
03:59:59 mies
04:01:00 geen teun
Sample output:
-- 12:00:00 --
12:00:04 aap
-- 02:09:40 --
02:09:40 een noot
02:09:41 twee noot
02:09:42 drie noot
-- 03:59:55 --
03:59:59 mies
So now, what did you really want to see?
:-).
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 05:01 PM
04-06-2004 05:01 PM
Re: orders
usage: perl time-range-grep.pl hh:mm:ss [minutes] < textfile
Where time-range-grep.pl contains:
($h,$m,$s)=split(/:/,shift);
$window=shift;
$window=5 unless ($window);
$h=0 if ($h==12);
$start=$h*60+$m;
while (<>) {
if (/(\d+):(\d+):\d+/) {
$t = ($1==12)? $2 : 60*$1 + $2;
print if (($t >= $start) && ($t < $start+$window)) ;
}
}
parse first argument into hours,minute
parse optional second argument into window, default 5
calculate start minute for period
find line with timestamps
calculate to minutes, making an exception of hour=12
in range? then print.
Sample input:
12:00:04 aap
02:09:40 een noot
02:09:41 twee noot
02:09:42 drie noot
03:59:59 mies
04:01:00 geen teun
Sample output:
# perl x.p 02:09:40 < x
02:09:40 een noot
02:09:41 twee noot
02:09:42 drie noot
# perl x.p 02:03:40 < x
# perl x.p 02:03:40 10 < x
02:09:40 een noot
02:09:41 twee noot
02:09:42 drie noot