Sponsored Content
Top Forums Shell Programming and Scripting Date format change in a csv file Post 302948829 by Smiling Dragon on Thursday 2nd of July 2015 07:17:14 PM
Old 07-02-2015
I'm going to assume this is some sort of *nix environment due to the requirement for it to be in shell.
The date command can do this for you:
Code:
date -d "$yourolddateformat" +"%d/%b/%Y %H:%M:%S"

If you need to do this via shell (I'll use bourne as it's the only shell you have on all *nix's), you'll just need to do a little lookup:
Code:
month=`echo "$yourolddateformat" | cut -d '/' -f 1`
day=`echo "$yourolddateformat" | cut -d '/' -f 2`
therest=`echo "$yourolddateformat" | cut -d '/' -f 3`
case $month in
  01)
    monthname="Jan"
    ;;
  02)
    monthname="Feb"
    ;;
  03)
    monthname="Mar"
    ;;
  04)
    monthname="Apr"
    ;;
  05)
    monthname="May"
    ;;
  06)
    monthname="Jun"
    ;;
  07)
    monthname="Jul"
    ;;
  08)
    monthname="Aug"
    ;;
  09)
    monthname="Sep"
    ;;
  10)
    monthname="Oct"
    ;;
  11)
    monthname="Nov"
    ;;
  12)
    monthname="Dec"
    ;;
  *)
    exit 1
    ;;
esac
echo "${day}/${monthname}/$therest"

The date command is tested, the script is not - some debug may be required.
Some editing will be required to make it fit you larger needs of course too but the core should be enough to get you 95% there.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
HTML::CalendarMonth::Locale(3pm)			User Contributed Perl Documentation			  HTML::CalendarMonth::Locale(3pm)

NAME
HTML::CalendarMonth::Locale - Front end class for DateTime::Locale SYNOPSIS
use HTML::CalendarMonth::Locale; my $loc = HTML::CalendarMonth::Locale->new( id => 'en_US' ); # list of days of the week for locale my @days = $loc->days; # list of months of the year for locale my @months = $loc->months; # the name of the current locale, as supplied the id parameter to # new() my $locale_name = $loc->id; # the actual DateTime::Locale object my $loc = $loc->loc; 1; DESCRIPTION
HTML::CalendarMonth utilizes the powerful locale capabilities of DateTime::Locale for rendering its calendars. The default locale is 'en_US' but many others are available. To see this list, invoke the class method HTML::CalendarMonth::Locale->locales() which in turn invokes DateTime::Locale::ids(). This module is mostly intended for internal usage within HTML::CalendarMonth, but some of its functionality may be of use for developers: METHODS
new() Constructor. Takes the following parameters: id Locale id, e.g. 'en_US'. full_days Specifies whether full day names or their abbreviations are desired. Default 0, use abbreviated days. full_months Specifies whether full month names or their abbreviations are desired. Default 1, use full months. id() Returns the locale id used during object construction. locale() Accessor method for the DateTime::Locale class, which in turn offers several class methods of specific interest. See DateTime::Locale. locale_map() Returns a hash of all available locales, mapping their id to their full name. loc() Accessor method for the DateTime::Locale instance as specified by "id". See DateTime::Locale. locales() Lists all available locale ids. Equivalent to locale()->ids(), or DateTime::Locale->ids(). days() Returns a list of days of the week, Sunday first. These are the actual unique day strings used for rendering calendars, so depending on which attributes were provided to "new()", this list will either be abbreviations or full names. The default uses abbreviated day names. Returns a list in list context or an array ref in scalar context. narrow_days() Returns a list of short day abbreviations, beginning with Sunday. The narrow abbreviations are not guaranteed to be unique (i.e. 'S' for both Sat and Sun). days_minmatch() Provides a hash reference containing minimal case-insensitive match strings for each day of the week, e.g., 'sa' for Saturday, 'm' for Monday, etc. months() Returns a list of months of the year, beginning with January. Depending on which attributes were provided to "new()", this list will either be full names or abbreviations. The default uses full names. Returns a list in list context or an array ref in scalar context. narrow_months() Returns a list of short month abbreviations, beginning with January. The narrow abbreviations are not guaranteed to be unique. months_minmatch() Provides a hash reference containing minimal case-insensitive match strings for each month of the year, e.g., 'n' for November, 'ja' for January, 'jul' for July, 'jun' for June, etc. daynums() Provides a hash reference containing day of week indices for each fully qualified day name as returned by days(). daynum($day) Provides the day of week index for a particular day name. dayname($day) Provides the fully qualified day name for a given string or day index. monthnums() Provides a hash reference containing month of year indices for each fully qualified month name as returned by months(). monthnum($month) Provides the month of year index for a particular month name. monthname($month) Provides the month name for a given string or month index. minmatch_hash(@list) This is the method used to generate the case-insensitive minimal match hash referenced above. Given an arbitrary list, a hash reference will be returned with minimal match strings as keys and the original strings as values. lc_minmatch_hash(@list) Same as minmatch_hash, except keys are forced to lower case. first_day_of_week() Returns a number from 0 to 6 representing the first day of the week for this locale, where 0 represents Sunday. AUTHOR
Matthew P. Sisk, <sisk@mojotoad.com> COPYRIGHT
Copyright (c) 2010 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
HTML::CalendarMonth(3), DateTime::Locale(3) perl v5.12.4 2011-09-28 HTML::CalendarMonth::Locale(3pm)
All times are GMT -4. The time now is 03:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy