Sponsored Content
Top Forums Shell Programming and Scripting Date format change in a csv file Post 302949032 by drl on Monday 6th of July 2015 09:45:05 AM
Old 07-06-2015
Hi.

A utility, dadd, in package dateutils can do the arithmetic and reformatting. It seems to be in many repositories ( e.g. arch, FreeBSD, Slackware, Mac OS X "brew" etc.), and source is available (github). I compiled it for an earlier version of Debian.

A single command suffices to process all conforming dates:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate date reformat, arithmetic, dateutils, dadd.
# "dadd" is part of dateutils, repository Debian/Jessie, MiNT, # Ubuntu, etc.
# Also: http://www.fresse.org/dateutils.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C dadd

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

# In : MM/DD/YYYY HH:MM:SS
# Out: DD/Mon/YYYY HH:MM:SS
pl " Results:"
dadd -S -i '%m/%d/%Y' +1mo -f '%d/%b/%Y' < $FILE

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
dadd 0.2.6

-----
 Input data file data1:
First line, no dates, some blank lines appear.
Today was: Mon Jul  6 08:18:06 CDT 2015

06/23/2015 20:59:12
Now is the time 06/23/2015 20:59:12 for all good men

No dates here.
When was 06/23/2015 20:59:12, another 06/23/2015 20:59:12, not 2015.06.23 20:59:12

Last line, no dates.

-----
 Results:
First line, no dates, some blank lines appear.
Today was: Mon Jul  6 08:18:06 CDT 2015

23/Jul/2015 20:59:12
Now is the time 23/Jul/2015 20:59:12 for all good men

No dates here.
When was 23/Jul/2015 20:59:12, another 23/Jul/2015 20:59:12, not 2015.06.23 20:59:12

Last line, no dates.

Sample input and output are best to supply with the original question, otherwise responders need to create them, which may or may not match what is really needed.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
 

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
LSIPC(1)							   User Commands							  LSIPC(1)

NAME
lsipc - show information on IPC facilities currently employed in the system SYNOPSIS
lsipc [options] DESCRIPTION
lsipc shows information on the inter-process communication facilities for which the calling process has read access. OPTIONS
-i, --id id Show full details on just the one resource element identified by id. This option needs to be combined with one of the three resource options: -m, -q or -s. It is possible to override the default output format for this option with the --list, --raw, --json or --export option. -g, --global Show system-wide usage and limits of IPC resources. This option may be combined with one of the three resource options: -m, -q or -s. The default is to show information about all resources. -h, --help Display help text and exit. -V, --version Display version information and exit. Resource options -m, --shmems Write information about active shared memory segments. -q, --queues Write information about active message queues. -s, --semaphores Write information about active semaphore sets. Output formatting -c, --creator Show creator and owner. -e, --export Output data in the format of NAME=VALUE. -J, --json Use the JSON output format. -l, --list Use the list output format. This is the default, except when --id is used. -n, --newline Display each piece of information on a separate line. --noheadings Do not print a header line. --notruncate Don't truncate output. -o, --output list Specify which output columns to print. Use --help to get a list of all supported columns. -b, --bytes Print size in bytes rather than in human readable format. -r, --raw Raw output (no columnation). -t, --time Write time information. The time of the last control operation that changed the access permissions for all facilities, the time of the last msgsnd(2) and msgrcv(2) operations on message queues, the time of the last shmat(2) and shmdt(2) operations on shared mem- ory, and the time of the last semop(2) operation on semaphores. --time-format type Display dates in short, full or iso format. The default is short, this time format is designed to be space efficient and human readable. -P, --numeric-perms Print numeric permissions in PERMS column. EXIT STATUS
0 if OK, 1 if incorrect arguments specified, 2 if a serious error occurs. SEE ALSO
ipcmk(1), ipcrm(1), msgrcv(2), msgsnd(2), semget(2), semop(2), shmat(2), shmdt(2), shmget(2) HISTORY
The lsipc utility is inspired by the ipcs utility. AUTHORS
Ondrej Oprala <ooprala@redhat.com> Karel Zak <kzak@redhat.com> AVAILABILITY
The lsipc command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils /util-linux/>. util-linux November 2015 LSIPC(1)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy