Date format change in a csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date format change in a csv file
# 8  
Old 07-05-2015
Hi Smiling Dragon, cfajohnson, Scrutinizer, & Aia,
If you look closely at the 1st post in this thread, you'll notice that the request is to find timestamps in unspecified fields in a CSV formatted file where the input timestamps are in the format MM/DD/YYYY HH:MM:SS and the output timestamps are supposed to be one month later in the format DD/Mon/YYYY HH:MM:SS.

So, there is no reason to believe that using / as a field separator on an input line will yield only three fields, that the first field will just contain a month number, nor that the third field will only contain a year and a timestamp. None of the code suggested so far makes any attempt to adjust the output month, to adjust the day field if the output month has fewer days than the input month, nor to adjust the year if the input month is 12.

Three days ago (less than an hour after the original post), I asked the submitter to provide us with more details and to show us what had been tried to solve this problem. I figured that the code that would be shown to us would clarify if the conversion from month number 06 to abbreviated month name Jul was intentional or a typo, would clarify if the field separator in the CSV file format was a comma or some other character, and would clarify whether every input field needed to be processed or if only certain fields need to be processed. Unfortunately, I am still waiting for a response.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 07-05-2015
I'm choosing to assume the month mismatch is an error on OPs part (dangerous I know but they've only talked about format in the text).
I've deliberately written the snippet to expect a date string and nothing else. As we've not seen any examples of the input stream I figure OP can sort that out Smilie

I hang my head in shame for using a GNU date feature, I actually hadn't realised it didn't exist on the bog-standard date <wrist slap>
# 10  
Old 07-05-2015
Quote:
Originally Posted by Smiling Dragon
[...]
I hang my head in shame for using a GNU date feature, I actually hadn't [realized] it didn't exist on the bog-standard date <wrist slap>
Why? The GNU utilities are so ubiquity that chances are that it would work for the OP as well as for anyone searching how to do something similar. In fact, you have used the GNU date all this time, without knowing you could have been using another crippled version.
# 11  
Old 07-05-2015
Quote:
Originally Posted by Aia
Why? The GNU utilities are so ubiquity that chances are that it would work for the OP as well as for anyone searching how to do something similar. In fact, you have used the GNU date all this time, without knowing you could have been using another crippled version.
Code:
s/crippled/standard/

This User Gave Thanks to cfajohnson For This Post:
# 12  
Old 07-05-2015
Quote:
Originally Posted by cfajohnson
Code:
s/crippled/standard/

Exactly, it can be substituted, since in the context I wrote it, it is interchangeable.

I am waiting for Don to appear. Smilie

Last edited by Aia; 07-05-2015 at 08:04 PM.. Reason: ;)
# 13  
Old 07-05-2015
Quote:
Originally Posted by Aia
Exactly, it can be substituted, since in the context I wrote it, it is interchangeable.
It seems that you don't care about portable code. It seems that you don't care about making suggestions that will work on any system likely to be used by the readers of this forum. It seems that you frequently make suggestions without testing them and believe that readers should be smart enough to ignore the suggestions you make that might not work on their system (on any system).

But, there are many users on these forums (including me) who are using UNIX systems that do not include GNU date.

Moderator's Comments:
Mod Comment Please do not denigrate users (like cfajohnson, Scrutinizer, and Smiling Dragon) who:
  • try to write portable code,
  • warn readers that extensions are being used that might not be portable, or
  • ask question submitters what OS and shell they're using so suggestions can be made that will work in the submitter's environment.

Please also review rule 2 in the rules you agreed to when you joined this forum.
# 14  
Old 07-05-2015
Don,

I do accept you have the right to interpret the rules as it suits you and when it suits you, as moderator. But I have not denigrated any user. Smiling Dragon made a comment I thought it was too hard on himself/herself, and I responded with my sincere opinion that I thought it was valuable his/her contribution. Of course, a smart-ass innuendo remark had it to be made about my chosen word "crippled".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Change date format in a file.

Hi all, I have a file as below, i would like the change the format of the time from "11/7/2019 20:12" to "2019-07-11 20:12:00" in the last coloumn. any awk solution on this. Input: 2,0,695016,1961612,497212,5800804,0,0,161,33,7605,12226,23,10,66,0,0,34,11/7/2019 20:10... (4 Replies)
Discussion started by: Raghuram717
4 Replies

2. Shell Programming and Scripting

Change date format in am/pm in csv files using UNIX

Hi All, I'm new to forum good to hear all. I stuck in converting date format in csv file using unix csv file contains as below ,750,0000000000000000GCJR, ,06/22/2016 14:48:44 I want to convert into as below ,750,0000000000000000GCJR, ,06/22/2016 02:48:44 PM Please reply asap..... (22 Replies)
Discussion started by: Raghureds
22 Replies

3. Shell Programming and Scripting

Need to change date format in a csv file using awk

Example: Input csv file 00245DLS,Sitel Ocala,12/31/2014,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel Ocala,12/31/2014,19:00,-1.00,-1.00,-1.00,-1.00 00245HB,Charlotte,01/01/2015,00:00,-1.00,-1.00,-1.00,0.00 Output csv file 00245DLS,Sitel Ocala,2014/12/31,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel... (8 Replies)
Discussion started by: adit
8 Replies

4. Shell Programming and Scripting

Datestamp format 2nd change in csv file (awk or sed)

I have a csv file formatted like this: 2014-08-21 18:06:26,A,B,12345,123,C,1232,26/08/14 18:07and I'm trying to change it to MM/DD/YYYY HH:MM for both occurances. I have got this: awk -F, 'NR <=1 {print;next}{"date +%d/%m/%Y\" \"%H:%m -d\""$1 "\""| getline dte;$1=dte}1' OFS="," test.csvThis... (6 Replies)
Discussion started by: say170
6 Replies

5. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

6. Shell Programming and Scripting

Changing date format in CSV file

I have a CSV file with a date format like this; 11/19/2012 17:37:00,1.372,121.6 11/19/2012 17:38:00,0.743,121.6 Want to change the time stamp to seconds after 1970 so I can get the data in rrdtool. For anyone interested, this is data from a TED5000 unit and is Kwatts and volts. Needs to... (3 Replies)
Discussion started by: ottsm
3 Replies

7. Shell Programming and Scripting

File date format how to change

Hi All, Below are the unix files taken by the help of ls -lrt -rw-r--r-- 1 kbehera Domain Users 293 Jul 27 13:33 sand.txt -rw-r--r-- 1 kbehera Domain Users 4 Jul 27 13:37 sand1.txt -rw-r--r-- 1 kbehera Domain Users 293 Jul 27 15:30 new_sand.txt -rw-r--r-- 1 kbehera Domain Users 0 Jul 27... (2 Replies)
Discussion started by: krupasindhu18
2 Replies

8. Shell Programming and Scripting

How to change date format in file

Hello! I have a textfile that look like this: "83d1:46:2b";"20091008190000";"Rögle BK - Skellefteå";"Swedish" "d4c:46:21";"20091008190000";"Södertälje - Brynäs";"Swedish" "d4b:46:2";"20091008190000";"HV 71 - Färjestad";"Swedish" "838:46:b";"20091010160000";"Skellefteå - HV 71";"Swedish"... (2 Replies)
Discussion started by: condmaster
2 Replies

9. Shell Programming and Scripting

Format a date in a csv file

So I have a csv file where the 3rd field is a date string in the format yyyy-mm-dd. I need to change it to mm/dd/yyyy. So each line in the csv file looks like: StringData,StringData,2009-02-17,12.345,StringData StringData,StringData,2009-02-16,65.789,StringData Any idea how I can keep... (5 Replies)
Discussion started by: rpiller
5 Replies

10. Shell Programming and Scripting

script to change the date format in a file

i have many files with date format of 6-9-2008 and i want a script that can change the format to 2008-06-09 Thanks (15 Replies)
Discussion started by: shehzad_m
15 Replies
Login or Register to Ask a Question