I have file which contains something like below
5,test,2019-09-27T11:06:23Z,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
4,test,2019-09-26T16:56:40Z,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26T16:54:25Z,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26T16:52:59Z,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26T16:46:52Z,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1
I want to trim the 3rd column 2019-09-27T11:06:23Z
to 2019-09-27
Basically I want to remove time and just keep date here.
4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1
I tried using awk with gsub
awk '{gsub("T","",$3);print}' test
But no luck, please help how can I achieve this.
Try:
Notes:
Your file is comma separated. Thus, you need to specify
-F,
so that, on input, each line is divided into fields based on commas.Since you want a comma-separated file on output, we also need to specify
OFS=,
.The first argument to
sub
(orgsub
) should be a regular expression not a string. In our case the regular expression should matchT
and everything after..*
means everything after.Since awk programmers often pride themselves on conciseness, you might want to remove
print
(too long-winded) and instead use: