Convert date format

Hi guys
I am looking to convert this kind of entry in a txt file

26/04/2008

to

April 2008

Note : this is not using the date command , these are date entries in a file

can i do this with sed ?

Refer to this thread :

Please use code tags for posting data, logs etc.
Also post 2-3 example lines of your data please, so that we can easier avoid pitfalls and provide a better solution.

Blind shot:

$ cat infile
03/02/2008 [AA] This is some data here.
26/04/2008 [BB] This is some data here.
$ sed '
s,/01/, January ,g
s,/02/, February ,g
s,/03/, March ,g
s,/04/, April ,g
' infile
03 February 2008 [AA] This is some data here.
26 April 2008 [BB] This is some data here.
1 Like

apologies, this is what i have

cat $1 | awk -F, '{print  $1 "," $2}' | sed '1d' | sed 's/IE//' | sed 's/^\(.\{7\}\)/\1 /' | sed 's/^\(.\{9\}\)/\1 /' | sed 's/,/ /'  | awk '{ print $4 " " $1 " "  $2 " "  $3}'| sort -k4 -n

This is the output, the output is what i want but i want to get the dates look like "February 2008"

26/04/2008 1416658 6 0266
13/01/2009 1414244 9 0333
14/04/2010 1418044 4 0367
19/01/2007 1514244 2 0395
13/04/2010 1617482 6 0472
27/04/2010 1516657 7 0597
04/02/2010 1612892 4 0602
02/02/2008 1516760 5 0636
25/11/2009 1510244 6 0850
30/03/2010 1414235 5 1639
21/02/2009 1510106 1 2687

I am sure there are other better ways of improving my current script but it does what i want it to do fine, so please just help me with the date bit

---------- Post updated at 07:05 AM ---------- Previous update was at 07:03 AM ----------

this looks fine , how can i incorporate this to what i have ?

Post the relevant input file to these 11 lines of example in code tags please.
There is a lot of duplicate calls of the tools so we can maybe put it all into 1 more compact command.
The initial cat is not needed at all.
awk and sed as well as most other tools that take input from files can open them on their own without it.

Hi.

See also a package of date utilities, among them dconv for conversion, as in this demonstration:

#!/usr/bin/env bash

# @(#) s1	Demonstrate date conversion of dates in file, dconv.
# Package dateutils in some Linux repositories, e.g. Debian 
# otherwise, see: http://www.fresse.org/dateutils/ or:
# https://github.com/hroptatyr/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 dconv

FILE=${1-data1}

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

pl " Results:"
# e.g. 26/04/2008 to April 2008
dconv -S -i '%d/%m/%Y' -f '%B %Y' < $FILE

exit 0

producing:

$ ./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
dconv 0.2.6

-----
 Input data file data1:
26/04/2008 1416658 6 0266
13/01/2009 1414244 9 0333
14/04/2010 1418044 4 0367
19/01/2007 1514244 2 0395
13/04/2010 1617482 6 0472
27/04/2010 1516657 7 0597
04/02/2010 1612892 4 0602
02/02/2008 1516760 5 0636
25/11/2009 1510244 6 0850
30/03/2010 1414235 5 1639
21/02/2009 1510106 1 2687

-----
 Results:
April 2008 1416658 6 0266
January 2009 1414244 9 0333
April 2010 1418044 4 0367
January 2007 1514244 2 0395
April 2010 1617482 6 0472
April 2010 1516657 7 0597
February 2010 1612892 4 0602
February 2008 1516760 5 0636
November 2009 1510244 6 0850
March 2010 1414235 5 1639
February 2009 1510106 1 2687

Best wishes ... cheers, drl

1 Like