Dear all,
I am having a file format like
2007-01-15 16:04:44 73125
2007-01-25 14:25:08 74302
2007-02-02 06:04:02 78580
2007-02-02 10:28:32 78614
2007-02-05 11:00:12 78800
2007-02-08 03:45:51 79184
2007-02-14 13:40:57 79805
2007-02-16 09:37:16 80006
2007-02-16 10:37:33 80017
2007-02-19 15:34:21 80209
2007-02-20 10:16:49 80271
2007-02-21 21:00:09 80525
2007-02-22 11:56:40 80569
2007-02-23 15:45:58 80706
2007-02-23 21:09:11 80724
2007-02-27 11:02:45 88726
2007-02-27 11:38:57 88733
2007-03-01 12:17:55 89060
2007-03-01 12:25:45 89061
2007-03-01 15:09:36 89098
2007-03-01 20:40:16 89136
2007-03-02 09:45:51 90240
2007-03-02 10:25:09 90477
2007-03-05 11:08:56 90657
2007-03-05 11:22:40 90659
2007-03-05 11:22:48 90660
2007-03-05 15:01:14 90698
2007-03-05 15:26:15 90705
2007-03-06 06:45:52 90770
2007-03-06 06:59:48 90773
2007-03-06 11:11:21 90806
2007-03-06 11:30:47 90811
2007-03-06 11:57:41 90822
2007-03-06 11:57:50 90820
2007-03-06 13:21:35 90834
2007-03-06 13:33:37 90838
2007-03-06 13:49:38 90840
2007-03-06 14:57:58 90848
2007-03-06 15:49:15 90858
2007-03-06 16:22:12 90864
2007-03-06 16:45:12 90868
2007-03-06 17:03:49 90871
2007-03-06 17:48:13 90879
2007-03-06 19:15:02 90885
How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
using awk or perl
|
|
0
|
|
|
|
Reply
|
a.meshach (1)
|
3/7/2007 7:39:54 AM |
|
Meshach wrote:
> Dear all,
>
> I am having a file format like
>
> 2007-01-15 16:04:44 73125
> 2007-01-25 14:25:08 74302
<...>
>
>
> How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
> using awk
/^2007-03-06/ { exit }
/^2007-02-02/ { y++ }
y { print }
> or perl
Wrong group :-)
/Thomas
|
|
0
|
|
|
|
Reply
|
Thomas
|
3/7/2007 8:12:39 AM
|
|
In article <esls5n$uql$1@news.al.sw.ericsson.se>,
Thomas Weidenfeller <nobody@ericsson.invalid> wrote:
>Meshach wrote:
>> Dear all,
>>
>> I am having a file format like
>>
>> 2007-01-15 16:04:44 73125
>> 2007-01-25 14:25:08 74302
>
><...>
>>
>>
>> How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
>> using awk
>
>/^2007-03-06/ { exit }
>/^2007-02-02/ { y++ }
>y { print }
The obvious shot is:
/^2007-03-06/,/^2007-02-02/
But then teh queston becomes "What does 'between' mean?" Does it
include the "edges"? If not, you can still do it this way, but you have
to include code to handle the edges. I've done it; it's not that hard.
>> or perl
>
>Wrong group :-)
As are C, assembler, Fortran, and Python (to name a few).
|
|
0
|
|
|
|
Reply
|
gazelle
|
3/7/2007 12:22:37 PM
|
|
=CF/=C7 Meshach =DD=E3=F1=E1=F8=E5:
> Dear all,
>
> I am having a file format like
>
> 2007-01-15 16:04:44 73125
> 2007-01-25 14:25:08 74302
> 2007-02-02 06:04:02 78580
> 2007-02-02 10:28:32 78614
> 2007-02-05 11:00:12 78800
> 2007-02-08 03:45:51 79184
> 2007-02-14 13:40:57 79805
> 2007-02-16 09:37:16 80006
> 2007-02-16 10:37:33 80017
> 2007-02-19 15:34:21 80209
> 2007-02-20 10:16:49 80271
> 2007-02-21 21:00:09 80525
> 2007-02-22 11:56:40 80569
> 2007-02-23 15:45:58 80706
> 2007-02-23 21:09:11 80724
> 2007-02-27 11:02:45 88726
> 2007-02-27 11:38:57 88733
> 2007-03-01 12:17:55 89060
> 2007-03-01 12:25:45 89061
> 2007-03-01 15:09:36 89098
> 2007-03-01 20:40:16 89136
> 2007-03-02 09:45:51 90240
> 2007-03-02 10:25:09 90477
> 2007-03-05 11:08:56 90657
> 2007-03-05 11:22:40 90659
> 2007-03-05 11:22:48 90660
> 2007-03-05 15:01:14 90698
> 2007-03-05 15:26:15 90705
> 2007-03-06 06:45:52 90770
> 2007-03-06 06:59:48 90773
> 2007-03-06 11:11:21 90806
> 2007-03-06 11:30:47 90811
> 2007-03-06 11:57:41 90822
> 2007-03-06 11:57:50 90820
> 2007-03-06 13:21:35 90834
> 2007-03-06 13:33:37 90838
> 2007-03-06 13:49:38 90840
> 2007-03-06 14:57:58 90848
> 2007-03-06 15:49:15 90858
> 2007-03-06 16:22:12 90864
> 2007-03-06 16:45:12 90868
> 2007-03-06 17:03:49 90871
> 2007-03-06 17:48:13 90879
> 2007-03-06 19:15:02 90885
>
>
> How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
> using awk or perl
Using ISO dates has the added benefit that you can treat them as
numbers.
{ split($1, a, "-"); date =3D a[1] a[2] a[3] }
date >=3D 20070202 && date <=3D 20070306
And you can use it in case your input isn't already sorted.
|
|
0
|
|
|
|
Reply
|
Vassilis
|
3/7/2007 2:18:58 PM
|
|
Meshach wrote:
> Dear all,
>
> I am having a file format like
>
> 2007-01-15 16:04:44 73125
> 2007-01-25 14:25:08 74302
> 2007-02-02 06:04:02 78580
> 2007-02-02 10:28:32 78614
> 2007-02-05 11:00:12 78800
> 2007-02-08 03:45:51 79184
> 2007-02-14 13:40:57 79805
> 2007-02-16 09:37:16 80006
> 2007-02-16 10:37:33 80017
> 2007-02-19 15:34:21 80209
> 2007-02-20 10:16:49 80271
> 2007-02-21 21:00:09 80525
> 2007-02-22 11:56:40 80569
> 2007-02-23 15:45:58 80706
> 2007-02-23 21:09:11 80724
> 2007-02-27 11:02:45 88726
> 2007-02-27 11:38:57 88733
> 2007-03-01 12:17:55 89060
> 2007-03-01 12:25:45 89061
> 2007-03-01 15:09:36 89098
> 2007-03-01 20:40:16 89136
> 2007-03-02 09:45:51 90240
> 2007-03-02 10:25:09 90477
> 2007-03-05 11:08:56 90657
> 2007-03-05 11:22:40 90659
> 2007-03-05 11:22:48 90660
> 2007-03-05 15:01:14 90698
> 2007-03-05 15:26:15 90705
> 2007-03-06 06:45:52 90770
> 2007-03-06 06:59:48 90773
> 2007-03-06 11:11:21 90806
> 2007-03-06 11:30:47 90811
> 2007-03-06 11:57:41 90822
> 2007-03-06 11:57:50 90820
> 2007-03-06 13:21:35 90834
> 2007-03-06 13:33:37 90838
> 2007-03-06 13:49:38 90840
> 2007-03-06 14:57:58 90848
> 2007-03-06 15:49:15 90858
> 2007-03-06 16:22:12 90864
> 2007-03-06 16:45:12 90868
> 2007-03-06 17:03:49 90871
> 2007-03-06 17:48:13 90879
> 2007-03-06 19:15:02 90885
>
>
> How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
> using awk or perl
>
If the dates are guaranteed to be sorted as above, see Kenny's post,
otherwise:
gsub(/-/,"") && $1 >= 20070202 && $1 <= 20070306
Regards,
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
3/8/2007 2:25:34 PM
|
|
On Mar 8, 10:25 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
> Meshach wrote:
> > Dear all,
>
> > I am having a file format like
>
> > 2007-01-15 16:04:44 73125
> > 2007-01-25 14:25:08 74302
> > 2007-02-02 06:04:02 78580
> > 2007-02-02 10:28:32 78614
> > 2007-02-05 11:00:12 78800
> > 2007-02-08 03:45:51 79184
> > 2007-02-14 13:40:57 79805
> > 2007-02-16 09:37:16 80006
> > 2007-02-16 10:37:33 80017
> > 2007-02-19 15:34:21 80209
> > 2007-02-20 10:16:49 80271
> > 2007-02-21 21:00:09 80525
> > 2007-02-22 11:56:40 80569
> > 2007-02-23 15:45:58 80706
> > 2007-02-23 21:09:11 80724
> > 2007-02-27 11:02:45 88726
> > 2007-02-27 11:38:57 88733
> > 2007-03-01 12:17:55 89060
> > 2007-03-01 12:25:45 89061
> > 2007-03-01 15:09:36 89098
> > 2007-03-01 20:40:16 89136
> > 2007-03-02 09:45:51 90240
> > 2007-03-02 10:25:09 90477
> > 2007-03-05 11:08:56 90657
> > 2007-03-05 11:22:40 90659
> > 2007-03-05 11:22:48 90660
> > 2007-03-05 15:01:14 90698
> > 2007-03-05 15:26:15 90705
> > 2007-03-06 06:45:52 90770
> > 2007-03-06 06:59:48 90773
> > 2007-03-06 11:11:21 90806
> > 2007-03-06 11:30:47 90811
> > 2007-03-06 11:57:41 90822
> > 2007-03-06 11:57:50 90820
> > 2007-03-06 13:21:35 90834
> > 2007-03-06 13:33:37 90838
> > 2007-03-06 13:49:38 90840
> > 2007-03-06 14:57:58 90848
> > 2007-03-06 15:49:15 90858
> > 2007-03-06 16:22:12 90864
> > 2007-03-06 16:45:12 90868
> > 2007-03-06 17:03:49 90871
> > 2007-03-06 17:48:13 90879
> > 2007-03-06 19:15:02 90885
>
> > How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
> > using awk or perl
>
> If the dates are guaranteed to be sorted as above, see Kenny's post,
> otherwise:
>
> gsub(/-/,"") && $1 >= 20070202 && $1 <= 20070306
>
> Regards,
>
> Ed.
I tried this:
awk '/2007-02-02/ || /2007-03-06/ { print }' file
What is the difference between || and , (comma) ?
(still learning Unix + awk)
|
|
0
|
|
|
|
Reply
|
Mag
|
3/25/2007 2:21:08 AM
|
|
Mag Gam wrote:
> On Mar 8, 10:25 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>Meshach wrote:
>>
>>>Dear all,
>>
>>>I am having a file format like
>>
>>> 2007-01-15 16:04:44 73125
>>> 2007-01-25 14:25:08 74302
>>> 2007-02-02 06:04:02 78580
>>> 2007-02-02 10:28:32 78614
>>> 2007-02-05 11:00:12 78800
>>> 2007-02-08 03:45:51 79184
>>> 2007-02-14 13:40:57 79805
>>> 2007-02-16 09:37:16 80006
>>> 2007-02-16 10:37:33 80017
>>> 2007-02-19 15:34:21 80209
>>> 2007-02-20 10:16:49 80271
>>> 2007-02-21 21:00:09 80525
>>> 2007-02-22 11:56:40 80569
>>> 2007-02-23 15:45:58 80706
>>> 2007-02-23 21:09:11 80724
>>> 2007-02-27 11:02:45 88726
>>> 2007-02-27 11:38:57 88733
>>> 2007-03-01 12:17:55 89060
>>> 2007-03-01 12:25:45 89061
>>> 2007-03-01 15:09:36 89098
>>> 2007-03-01 20:40:16 89136
>>> 2007-03-02 09:45:51 90240
>>> 2007-03-02 10:25:09 90477
>>> 2007-03-05 11:08:56 90657
>>> 2007-03-05 11:22:40 90659
>>> 2007-03-05 11:22:48 90660
>>> 2007-03-05 15:01:14 90698
>>> 2007-03-05 15:26:15 90705
>>> 2007-03-06 06:45:52 90770
>>> 2007-03-06 06:59:48 90773
>>> 2007-03-06 11:11:21 90806
>>> 2007-03-06 11:30:47 90811
>>> 2007-03-06 11:57:41 90822
>>> 2007-03-06 11:57:50 90820
>>> 2007-03-06 13:21:35 90834
>>> 2007-03-06 13:33:37 90838
>>> 2007-03-06 13:49:38 90840
>>> 2007-03-06 14:57:58 90848
>>> 2007-03-06 15:49:15 90858
>>> 2007-03-06 16:22:12 90864
>>> 2007-03-06 16:45:12 90868
>>> 2007-03-06 17:03:49 90871
>>> 2007-03-06 17:48:13 90879
>>> 2007-03-06 19:15:02 90885
>>
>>>How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
>>>using awk or perl
>>
>>If the dates are guaranteed to be sorted as above, see Kenny's post,
>>otherwise:
>>
>>gsub(/-/,"") && $1 >= 20070202 && $1 <= 20070306
>>
>>Regards,
>>
>> Ed.
>
>
> I tried this:
> awk '/2007-02-02/ || /2007-03-06/ { print }' file
>
> What is the difference between || and , (comma) ?
The former d1||d2 matches any lines that contain either of the two dates,
d1 or d2.
The latter d1,d2 matches all lines starting from lines containing d1 and
ending on a line with d2; it specifies a _range_ where the two bounds are
defined by the patterns (there may be multiple blocks of data that match).
Janis
>
> (still learning Unix + awk)
>
|
|
0
|
|
|
|
Reply
|
Janis
|
3/25/2007 3:11:22 AM
|
|
On Mar 7, 2:39 am, "Meshach" <a.mesh...@gmail.com> wrote:
> Dear all,
>
> I am having a file format like
>
> 2007-01-15 16:04:44 73125
> 2007-01-25 14:25:08 74302
> 2007-02-02 06:04:02 78580
> 2007-02-02 10:28:32 78614
> 2007-02-05 11:00:12 78800
> 2007-02-08 03:45:51 79184
> 2007-02-14 13:40:57 79805
> 2007-02-16 09:37:16 80006
> 2007-02-16 10:37:33 80017
> 2007-02-19 15:34:21 80209
> 2007-02-20 10:16:49 80271
> 2007-02-21 21:00:09 80525
> 2007-02-22 11:56:40 80569
> 2007-02-23 15:45:58 80706
> 2007-02-23 21:09:11 80724
> 2007-02-27 11:02:45 88726
> 2007-02-27 11:38:57 88733
> 2007-03-01 12:17:55 89060
> 2007-03-01 12:25:45 89061
> 2007-03-01 15:09:36 89098
> 2007-03-01 20:40:16 89136
> 2007-03-02 09:45:51 90240
> 2007-03-02 10:25:09 90477
> 2007-03-05 11:08:56 90657
> 2007-03-05 11:22:40 90659
> 2007-03-05 11:22:48 90660
> 2007-03-05 15:01:14 90698
> 2007-03-05 15:26:15 90705
> 2007-03-06 06:45:52 90770
> 2007-03-06 06:59:48 90773
> 2007-03-06 11:11:21 90806
> 2007-03-06 11:30:47 90811
> 2007-03-06 11:57:41 90822
> 2007-03-06 11:57:50 90820
> 2007-03-06 13:21:35 90834
> 2007-03-06 13:33:37 90838
> 2007-03-06 13:49:38 90840
> 2007-03-06 14:57:58 90848
> 2007-03-06 15:49:15 90858
> 2007-03-06 16:22:12 90864
> 2007-03-06 16:45:12 90868
> 2007-03-06 17:03:49 90871
> 2007-03-06 17:48:13 90879
> 2007-03-06 19:15:02 90885
>
> How can I list the record between 2007-02-02(yy-mm-dd) and 2007-03-06
> using awk or perl
(("2007-02-02"<=$1)&&($1<="2007-03-06")){print;}
|
|
0
|
|
|
|
Reply
|
Joseph
|
3/25/2007 7:55:19 PM
|
|
|
7 Replies
459 Views
(page loaded in 0.102 seconds)
|