My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
$ sort -k1 <1111> Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?
Regards,
HZ
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?
Regards,
HZ
On 19-Apr-2022 at 7:50:04PM PDT, "hongyi.zhao@gmail.com" <hongyi.zhao@gmail.com> wrote:
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows: >>
$ sort -k1 <1111> Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this
problem?
Regards,
HZ
Sort does have a flag to sort on month abbreviations, but you really want to sort on the entire date which is all three fields. You'll have to add a field that's the concatination of all three fields in the form YYYY-MM-DD where you convert the string month into a 01-12 number, then sort on that. I don't see a
way to do this with just the shell built-ins or standard utilities.
You'll
have to write a perl or python script to process this data line by line.
Or pull all the data into Excel and use it's sort columns feature. That's probably the easiest way you'll be able to deal with this given your questions
on this forum.
On 20.04.2022 04:50, hongy...@gmail.com wrote:
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?Generally I'd try to avoid pathological date formats in the first place
and create and use ISO-dates or convert the dates to ISO format.
Otherwise we probably need more or less clumsy workarounds, e.g. like
while read usdate
do date -d "${usdate}" "+%Y-%m-%d ${usdate}"
done <your_file | sort | cut -d\ -f2-
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?
On 20/04/2022 at 04.50, hongy...@gmail.com wrote:
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?Yeah, the same hint you are always given and never take:
read the man page and use the information from there.
For dates in the format shown above this should work:
$ sort -b -k3n,3 -k1M,1 -k2n,2 < 1111
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
cut -d\ -f2-
cut: the delimiter must be a single character
Try 'cut --help' for more information.
On Wed, 20 Apr 2022 00:06:03 -0700 (PDT), "hongy...@gmail.com" <hongy...@gmail.com> wrote:
cut -d\ -f2-Did you try 'man cut' ?
cut: the delimiter must be a single character
Try 'cut --help' for more information.
Did you even try to solve this yourself.
What about cut -d ' ' -f2- ?
On Wednesday, April 20, 2022 at 7:44:35 PM UTC+8, Kees Nuyt wrote:
On Wed, 20 Apr 2022 00:06:03 -0700 (PDT), "hongy...@gmail.com"
<hongy...@gmail.com> wrote:
cut -d\ -f2-Did you try 'man cut' ?
cut: the delimiter must be a single character
Try 'cut --help' for more information.
Did you even try to solve this yourself.
What about cut -d ' ' -f2- ?
But this code snippet is given by Janis Papanagnou, an expert in this group. So I don't know how he can write like this.
It's only Hongyi Zhao's fault rather indirectly for using Google Groups.
The -d\ -f2- is correct when I view Janis's post in my newsreader, but
it has already been broken when I view it in GG.
On 4/20/2022 7:07 PM, hongy...@gmail.com wrote:
On Wednesday, April 20, 2022 at 7:44:35 PM UTC+8, Kees Nuyt wrote:
On Wed, 20 Apr 2022 00:06:03 -0700 (PDT), "hongy...@gmail.com"
<hongy...@gmail.com> wrote:
cut -d\ -f2-
cut: the delimiter must be a single character
Try 'cut --help' for more information.
Did you try 'man cut' ?
Did you even try to solve this yourself.
What about cut -d ' ' -f2- ?
But this code snippet is given by Janis Papanagnou, an expert in this
group. So I don't know how he can write like this.
They didn't, you copy/pasted it wrong. Take a few seconds to look at
the code Janis provided and think about the way in which the code you executed is not the same as that and what that means to the shell interpreting it.
On Wednesday, April 20, 2022 at 12:36:21 PM UTC+8, Janis Papanagnou wrote:
On 20.04.2022 04:50, hongy...@gmail.com wrote:
My data includes the following data formats in each row:Generally I'd try to avoid pathological date formats in the first place
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows: >>>
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?
and create and use ISO-dates or convert the dates to ISO format.
Otherwise we probably need more or less clumsy workarounds, e.g. like
while read usdate
do date -d "${usdate}" "+%Y-%m-%d ${usdate}"
done <your_file | sort | cut -d\ -f2-
$ cat usdate
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
$ while read usdate
do date -d "${usdate}" "+%Y-%m-%d ${usdate}"
done <usdate | sort | cut -d\ -f2-
cut: the delimiter must be a single character
Try 'cut --help' for more information.
Ed Morton <mortonspam@gmail.com> writes:[...]
On 4/20/2022 7:07 PM, hongy...@gmail.com wrote:
On Wednesday, April 20, 2022 at 7:44:35 PM UTC+8, Kees Nuyt wrote:
On Wed, 20 Apr 2022 00:06:03 -0700 (PDT), "hongy...@gmail.com"
<hongy...@gmail.com> wrote:
cut -d\ -f2-
cut: the delimiter must be a single character
Try 'cut --help' for more information.
It's only Hongyi Zhao's fault rather indirectly for using Google Groups.
The -d\ -f2- is correct when I view Janis's post in my newsreader, but
it has already been broken when I view it in GG. And now there's
nothing one can do but spot and correct the fault by hand. Copying the
text just copies the error GG has introduced.
GG has been going downhill for a long time (yes, hard to imagine there
was ever a hill it could go down), but now it seems that 100% correct
advice will be seen by the GG world as wrong for ever!
On 21/04/2022 11:38, Ben wrote:
It's only Hongyi Zhao's fault rather indirectly for using Google Groups.
The -d\ -f2- is correct when I view Janis's post in my newsreader, but
it has already been broken when I view it in GG.
HTML is probably the culprit.
Multiple spaces (and tabs) are 'condensed' into one space.
On Thu, 21 Apr 2022 11:38:53 +0100
Ben <ben.usenet@bsb.me.uk> wrote:
Ed Morton <mortonspam@gmail.com> writes:[...]
On 4/20/2022 7:07 PM, hongy...@gmail.com wrote:
On Wednesday, April 20, 2022 at 7:44:35 PM UTC+8, Kees Nuyt wrote:
On Wed, 20 Apr 2022 00:06:03 -0700 (PDT), "hongy...@gmail.com"
<hongy...@gmail.com> wrote:
cut -d\ -f2-
cut: the delimiter must be a single character
Try 'cut --help' for more information.
It's only Hongyi Zhao's fault rather indirectly for using Google Groups.
The -d\ -f2- is correct when I view Janis's post in my newsreader, but
it has already been broken when I view it in GG. And now there's
nothing one can do but spot and correct the fault by hand. Copying the
text just copies the error GG has introduced.
GG has been going downhill for a long time (yes, hard to imagine there
was ever a hill it could go down), but now it seems that 100% correct
advice will be seen by the GG world as wrong for ever!
Not necessarily for ever. If googlegroups internally stores the messages
as they came through NNTP then , when the HTML rendering bug gets fixed ,
the post (and all the others which screw up indendation) will display correctly. On the other hand , messages which respond to a googlegroups
post through googlegroups , may end up having the mistake forever.
On 20/04/2022 at 04.50, hongy...@gmail.com wrote:
My data includes the following data formats in each row:
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows:
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?Yeah, the same hint you are always given and never take:
read the man page and use the information from there.
For dates in the format shown above this should work:
$ sort -b -k3n,3 -k1M,1 -k2n,2 < 1111
On Wednesday, April 20, 2022 at 12:36:21 PM UTC+8, Janis Papanagnou wrote:
On 20.04.2022 04:50, hongy...@gmail.com wrote:
My data includes the following data formats in each row:Generally I'd try to avoid pathological date formats in the first place
$ cat 1111
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
I want to sort them according to the date, and tried with sort as follows: >>>
$ sort -k1 < 1111
Apr 30 2019
Jan 2 2022
Jul 23 2021
Oct 24 2004
Obviously, this doesn't work as expected. Any hints for dealing with this problem?
and create and use ISO-dates or convert the dates to ISO format.
Otherwise we probably need more or less clumsy workarounds, e.g. like
while read usdate
do date -d "${usdate}" "+%Y-%m-%d ${usdate}"
done <your_file | sort | cut -d\ -f2-
$ cat usdate
Jul 23 2021
Apr 30 2019
Jan 2 2022
Oct 24 2004
$ while read usdate
do date -d "${usdate}" "+%Y-%m-%d ${usdate}"
done <usdate | sort | cut -d\ -f2-
cut: the delimiter must be a single character
Try 'cut --help' for more information.
I'd expect that you can read and understand that code, or can
"analyze" it
On 22/04/2022 10:03, Janis Papanagnou wrote:
I'd expect that you can read and understand that code, or can
"analyze" it
As if he would!
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 422 |
Nodes: | 16 (3 / 13) |
Uptime: | 196:21:29 |
Calls: | 8,951 |
Calls today: | 2 |
Files: | 13,352 |
Messages: | 5,992,474 |