I've searched unsuccessfully for a solution to this problem.
I have a CSV file with a date field I'm trying to sort by both month and day.
CSV format :
name,email,phone,date
The date field format is m/d/yy
as in 1/3/84
I can sort by month
sort -t',' -n -k4 < $file`
but I can't wrap my head around splitting the date field and then sorting on k1 and k2, if that makes sense or is even remotely close.
This is clearly wrong `
cat $file | sort -t',' -n -k4 | sort -t'/' -n -k1 -k2
as the output is only sorted by day and k1 includes everything before the first /
.
Looking to learn, not be spoon-fed.
EDIT:
Sample CSV
Name,Email,Phone,Birthday
MarkW.,[email protected],(555) 444-4444,6/24/85
GeorgeT.,[email protected],(555) 555-1413,4/2/82
BobA.,[email protected],(555) 555-5050,11/15/85
TimP.,[email protected],,4/11/18
JohnM.,[email protected],(555) 555-1317,4/25/13
MikeT.,[email protected],(555) 555-2114,4/10/91
BobR.,[email protected],(555) 555-1383,7/13/14
TomW.,[email protected],(555) 555-1980,12/25/08
JamesS.,[email protected],(555) 555-2150,6/12/15
TimC.,[email protected],(555) 555-8048,3/17/08
WallyG.,[email protected],,7/21/00
KeithD.,[email protected],,12/29/12
DaveM.,[email protected],,1/10/48
DanMc.,[email protected],(555) 555-6863,5/19/88
DickM.,[email protected],(555) 555-9333,11/23/13
KenB.,[email protected],(555) 555-6891,1/2/04
DaveMc.,[email protected],,
MichaelL.,[email protected],(555) 555-1575,9/15/13
RoryB.,[email protected],(555) 555-555,1/25/17
Sample Output, best I've been able to come up with using
sort -t',' -n -k4 < $file
Expected output would be 1/10/84 appearing after 1/2/04 for example.
DaveMc.,[email protected],,
Name,Email,Phone,Birthday
DaveM.,[email protected],,1/10/48
KenB.,[email protected],(555) 555-6891,1/2/04
RoryB.,[email protected],(555) 555-555,1/25/17
TimC.,[email protected],(555) 555-8048,3/17/08
GeorgeT.,[email protected],(555) 555-1413,4/2/82
JohnM.,[email protected],(555) 555-1317,4/25/13
MikeT.,[email protected],(555) 555-2114,4/10/91
TimP.,[email protected],,4/11/18
DanMc.,[email protected],(555) 555-6863,5/19/88
JamesS.,[email protected],(555) 555-2150,6/12/15
MarkW.,[email protected],(555) 444-4444,6/24/85
BobR.,[email protected],(555) 555-1383,7/13/14
WallyG.,[email protected],,7/21/00
MichaelL.,[email protected],(555) 555-1575,9/15/13
BobA.,[email protected],(555) 555-5050,11/15/85
DickM.,[email protected],(555) 555-9333,11/23/13
KeithD.,[email protected],,12/29/12
TomW.,[email protected],(555) 555-1980,12/25/08
It's sorted by month but I'm trying to also sort by day