-
-
Save pgtwitter/1f344ff8c56847dba836953c80487785 to your computer and use it in GitHub Desktop.
"%b %d, %Y" to "%Y-%m-%d" using awk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# reference: https://stackoverflow.com/questions/38262829/awk-command-to-convert-date-format-in-a-file#answer-38271260 | |
/usr/bin/awk -F'\t' '{ | |
split($1,a," "); | |
printf "%04d-%02d-%02d", a[3], (match("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC",toupper(a[1]))+2)/3, a[2]; | |
for(i=2;i<=NF;i++)printf("\t%s",$i); | |
printf("\n") | |
}' << EOF | |
Sep 9, 2024 142.1234 143.1234 142.1234 142.1234 142.1234 | |
Aug 8, 2024 146.1234 147.1234 145.1234 146.1234 146.1234 | |
Jul 5, 2024 161.1234 161.1234 160.1234 161.1234 161.1234 | |
Jun 6, 2024 155.1234 156.1234 155.1234 155.1234 155.1234 | |
May 3, 2024 153.1234 153.1234 151.1234 153.1234 153.1234 | |
Apr 4, 2024 151.1234 151.1234 151.1234 151.1234 151.1234 | |
Mar 1, 2024 150.1234 150.1234 150.1234 150.1234 150.1234 | |
Feb 2, 2024 146.1234 148.1234 146.1234 146.1234 146.1234 | |
Jan 1, 2024 140.1234 141.1234 140.1234 140.1234 140.1234 | |
Dec 12, 2023 146.1234 146.1234 144.1234 146.1234 146.1234 | |
Nov 10, 2023 151.1234 151.1234 151.1234 151.1234 151.1234 | |
Oct 10, 2023 148.1234 149.1234 148.1234 148.1234 148.1234 | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
--
2024-09-09 142.1234 143.1234 142.1234 142.1234 142.1234
2024-08-08 146.1234 147.1234 145.1234 146.1234 146.1234
2024-07-05 161.1234 161.1234 160.1234 161.1234 161.1234
2024-06-06 155.1234 156.1234 155.1234 155.1234 155.1234
2024-05-03 153.1234 153.1234 151.1234 153.1234 153.1234
2024-04-04 151.1234 151.1234 151.1234 151.1234 151.1234
2024-03-01 150.1234 150.1234 150.1234 150.1234 150.1234
2024-02-02 146.1234 148.1234 146.1234 146.1234 146.1234
2024-01-01 140.1234 141.1234 140.1234 140.1234 140.1234
2023-12-12 146.1234 146.1234 144.1234 146.1234 146.1234
2023-11-10 151.1234 151.1234 151.1234 151.1234 151.1234
2023-10-10 148.1234 149.1234 148.1234 148.1234 148.1234
--