I have the date written in csv file as 19/10/2014.I want it in the format 19-Oct-2014
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have the date in a CSV file as 19/10/2014
. I want it in the format 19-Oct-2014
. I am new to Unix so I don't know any command.
date csv text-formatting
add a comment |Â
up vote
1
down vote
favorite
I have the date in a CSV file as 19/10/2014
. I want it in the format 19-Oct-2014
. I am new to Unix so I don't know any command.
date csv text-formatting
1
Please post at least one line of your CSV file so that I can adjust theawk
script below!
â Ned64
Feb 16 at 10:56
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have the date in a CSV file as 19/10/2014
. I want it in the format 19-Oct-2014
. I am new to Unix so I don't know any command.
date csv text-formatting
I have the date in a CSV file as 19/10/2014
. I want it in the format 19-Oct-2014
. I am new to Unix so I don't know any command.
date csv text-formatting
edited Feb 16 at 10:56
yeti
2,36611223
2,36611223
asked Feb 16 at 10:32
jpyngas
91
91
1
Please post at least one line of your CSV file so that I can adjust theawk
script below!
â Ned64
Feb 16 at 10:56
add a comment |Â
1
Please post at least one line of your CSV file so that I can adjust theawk
script below!
â Ned64
Feb 16 at 10:56
1
1
Please post at least one line of your CSV file so that I can adjust the
awk
script below!â Ned64
Feb 16 at 10:56
Please post at least one line of your CSV file so that I can adjust the
awk
script below!â Ned64
Feb 16 at 10:56
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
2
down vote
A solution completely in GNU awk is as follows:
awk ' split($0,slt,"/");datspec=mktime(slt[3]" "slt[2]" "slt[1]" 00 00 00");print strftime("%d-%b-%Y",datspec) ' <<< "19/10/2014"
Taking the date as the input, we first split the data into an array (slt) to attain the date,month and year. We then use awk's mktime function to get a date spec that is then used by awk's sttftime function to get the date in the correct format.
With a csv, $0 would be the number corresponding to the comma delimited field that has the date.
add a comment |Â
up vote
2
down vote
The date
command can format this for you:
date -d "2014-10-19" +%d-%b-%Y
which yields
19-Oct-2014
If you give sample lines of your file we can script it for you.
One way is using awk
:
echo zzz,19/10/2014,aaa,bbb | awk -F, ' getline date; OFS=","; $2=date; print; close(cmd)'
which gives
zzz,19-Oct-2014,aaa,bbb
Assuming here that you wish to modifiy the 2nd field. Adjust "split($2,dateelem,"/");"
in the awk
script to change the field (column) number your date appears in
When processing a large file, you'll need to close the pipe after you read from it:close cmd
â glenn jackman
Feb 16 at 14:36
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
add a comment |Â
up vote
0
down vote
perl can do it, but it's not really for beginners. However, parsing dates is best handled by proper date handling libraries. perl has one in the box, Time::Piece
$ cat file
a,b,19/10/2014,d
$ perl -MTime::Piece -F, -lane '
$F[2] = Time::Piece->strptime($F[2], "%d/%m/%Y")->strftime("%d-%b-%Y");
print join ",", @F
' file
a,b,19-Oct-2014,d
add a comment |Â
up vote
0
down vote
I have done by below method
command
j=`date -d "2014/10/19" +%b`;echo "19/10/2014" | awk -v j="$j" -F "/" 'print $1"-"j"-"$3'
Output
19-Oct-2014
add a comment |Â
up vote
0
down vote
Another awk
approach. Uses basic awk
functionality, so likely to work with non-GNU implementations.
$ cat infile
foo,19/10/2014,bar
foo2,19/01/2015,bar2
$ awk -F, 'print $1","substr($2,0,2)"-"substr("JanFebMarAprMayJunJulAugSepOctNovDec",substr($2,4,2)*3-2,3)"-"substr($2,7,4)","$3' infile
foo,19-Oct-2014,bar
foo2,19-Jan-2015,bar2
$
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
A solution completely in GNU awk is as follows:
awk ' split($0,slt,"/");datspec=mktime(slt[3]" "slt[2]" "slt[1]" 00 00 00");print strftime("%d-%b-%Y",datspec) ' <<< "19/10/2014"
Taking the date as the input, we first split the data into an array (slt) to attain the date,month and year. We then use awk's mktime function to get a date spec that is then used by awk's sttftime function to get the date in the correct format.
With a csv, $0 would be the number corresponding to the comma delimited field that has the date.
add a comment |Â
up vote
2
down vote
A solution completely in GNU awk is as follows:
awk ' split($0,slt,"/");datspec=mktime(slt[3]" "slt[2]" "slt[1]" 00 00 00");print strftime("%d-%b-%Y",datspec) ' <<< "19/10/2014"
Taking the date as the input, we first split the data into an array (slt) to attain the date,month and year. We then use awk's mktime function to get a date spec that is then used by awk's sttftime function to get the date in the correct format.
With a csv, $0 would be the number corresponding to the comma delimited field that has the date.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
A solution completely in GNU awk is as follows:
awk ' split($0,slt,"/");datspec=mktime(slt[3]" "slt[2]" "slt[1]" 00 00 00");print strftime("%d-%b-%Y",datspec) ' <<< "19/10/2014"
Taking the date as the input, we first split the data into an array (slt) to attain the date,month and year. We then use awk's mktime function to get a date spec that is then used by awk's sttftime function to get the date in the correct format.
With a csv, $0 would be the number corresponding to the comma delimited field that has the date.
A solution completely in GNU awk is as follows:
awk ' split($0,slt,"/");datspec=mktime(slt[3]" "slt[2]" "slt[1]" 00 00 00");print strftime("%d-%b-%Y",datspec) ' <<< "19/10/2014"
Taking the date as the input, we first split the data into an array (slt) to attain the date,month and year. We then use awk's mktime function to get a date spec that is then used by awk's sttftime function to get the date in the correct format.
With a csv, $0 would be the number corresponding to the comma delimited field that has the date.
edited Feb 16 at 11:19
Kusalananda
103k13202318
103k13202318
answered Feb 16 at 11:03
Raman Sailopal
1,18317
1,18317
add a comment |Â
add a comment |Â
up vote
2
down vote
The date
command can format this for you:
date -d "2014-10-19" +%d-%b-%Y
which yields
19-Oct-2014
If you give sample lines of your file we can script it for you.
One way is using awk
:
echo zzz,19/10/2014,aaa,bbb | awk -F, ' getline date; OFS=","; $2=date; print; close(cmd)'
which gives
zzz,19-Oct-2014,aaa,bbb
Assuming here that you wish to modifiy the 2nd field. Adjust "split($2,dateelem,"/");"
in the awk
script to change the field (column) number your date appears in
When processing a large file, you'll need to close the pipe after you read from it:close cmd
â glenn jackman
Feb 16 at 14:36
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
add a comment |Â
up vote
2
down vote
The date
command can format this for you:
date -d "2014-10-19" +%d-%b-%Y
which yields
19-Oct-2014
If you give sample lines of your file we can script it for you.
One way is using awk
:
echo zzz,19/10/2014,aaa,bbb | awk -F, ' getline date; OFS=","; $2=date; print; close(cmd)'
which gives
zzz,19-Oct-2014,aaa,bbb
Assuming here that you wish to modifiy the 2nd field. Adjust "split($2,dateelem,"/");"
in the awk
script to change the field (column) number your date appears in
When processing a large file, you'll need to close the pipe after you read from it:close cmd
â glenn jackman
Feb 16 at 14:36
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
add a comment |Â
up vote
2
down vote
up vote
2
down vote
The date
command can format this for you:
date -d "2014-10-19" +%d-%b-%Y
which yields
19-Oct-2014
If you give sample lines of your file we can script it for you.
One way is using awk
:
echo zzz,19/10/2014,aaa,bbb | awk -F, ' getline date; OFS=","; $2=date; print; close(cmd)'
which gives
zzz,19-Oct-2014,aaa,bbb
Assuming here that you wish to modifiy the 2nd field. Adjust "split($2,dateelem,"/");"
in the awk
script to change the field (column) number your date appears in
The date
command can format this for you:
date -d "2014-10-19" +%d-%b-%Y
which yields
19-Oct-2014
If you give sample lines of your file we can script it for you.
One way is using awk
:
echo zzz,19/10/2014,aaa,bbb | awk -F, ' getline date; OFS=","; $2=date; print; close(cmd)'
which gives
zzz,19-Oct-2014,aaa,bbb
Assuming here that you wish to modifiy the 2nd field. Adjust "split($2,dateelem,"/");"
in the awk
script to change the field (column) number your date appears in
edited Feb 16 at 21:55
answered Feb 16 at 10:44
Ned64
2,44411035
2,44411035
When processing a large file, you'll need to close the pipe after you read from it:close cmd
â glenn jackman
Feb 16 at 14:36
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
add a comment |Â
When processing a large file, you'll need to close the pipe after you read from it:close cmd
â glenn jackman
Feb 16 at 14:36
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
When processing a large file, you'll need to close the pipe after you read from it:
close cmd
â glenn jackman
Feb 16 at 14:36
When processing a large file, you'll need to close the pipe after you read from it:
close cmd
â glenn jackman
Feb 16 at 14:36
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
@glennjackman Thanks, you are right, editing...
â Ned64
Feb 16 at 21:51
add a comment |Â
up vote
0
down vote
perl can do it, but it's not really for beginners. However, parsing dates is best handled by proper date handling libraries. perl has one in the box, Time::Piece
$ cat file
a,b,19/10/2014,d
$ perl -MTime::Piece -F, -lane '
$F[2] = Time::Piece->strptime($F[2], "%d/%m/%Y")->strftime("%d-%b-%Y");
print join ",", @F
' file
a,b,19-Oct-2014,d
add a comment |Â
up vote
0
down vote
perl can do it, but it's not really for beginners. However, parsing dates is best handled by proper date handling libraries. perl has one in the box, Time::Piece
$ cat file
a,b,19/10/2014,d
$ perl -MTime::Piece -F, -lane '
$F[2] = Time::Piece->strptime($F[2], "%d/%m/%Y")->strftime("%d-%b-%Y");
print join ",", @F
' file
a,b,19-Oct-2014,d
add a comment |Â
up vote
0
down vote
up vote
0
down vote
perl can do it, but it's not really for beginners. However, parsing dates is best handled by proper date handling libraries. perl has one in the box, Time::Piece
$ cat file
a,b,19/10/2014,d
$ perl -MTime::Piece -F, -lane '
$F[2] = Time::Piece->strptime($F[2], "%d/%m/%Y")->strftime("%d-%b-%Y");
print join ",", @F
' file
a,b,19-Oct-2014,d
perl can do it, but it's not really for beginners. However, parsing dates is best handled by proper date handling libraries. perl has one in the box, Time::Piece
$ cat file
a,b,19/10/2014,d
$ perl -MTime::Piece -F, -lane '
$F[2] = Time::Piece->strptime($F[2], "%d/%m/%Y")->strftime("%d-%b-%Y");
print join ",", @F
' file
a,b,19-Oct-2014,d
answered Feb 16 at 14:31
glenn jackman
46.3k265102
46.3k265102
add a comment |Â
add a comment |Â
up vote
0
down vote
I have done by below method
command
j=`date -d "2014/10/19" +%b`;echo "19/10/2014" | awk -v j="$j" -F "/" 'print $1"-"j"-"$3'
Output
19-Oct-2014
add a comment |Â
up vote
0
down vote
I have done by below method
command
j=`date -d "2014/10/19" +%b`;echo "19/10/2014" | awk -v j="$j" -F "/" 'print $1"-"j"-"$3'
Output
19-Oct-2014
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have done by below method
command
j=`date -d "2014/10/19" +%b`;echo "19/10/2014" | awk -v j="$j" -F "/" 'print $1"-"j"-"$3'
Output
19-Oct-2014
I have done by below method
command
j=`date -d "2014/10/19" +%b`;echo "19/10/2014" | awk -v j="$j" -F "/" 'print $1"-"j"-"$3'
Output
19-Oct-2014
answered Feb 16 at 15:23
Praveen Kumar BS
1,010128
1,010128
add a comment |Â
add a comment |Â
up vote
0
down vote
Another awk
approach. Uses basic awk
functionality, so likely to work with non-GNU implementations.
$ cat infile
foo,19/10/2014,bar
foo2,19/01/2015,bar2
$ awk -F, 'print $1","substr($2,0,2)"-"substr("JanFebMarAprMayJunJulAugSepOctNovDec",substr($2,4,2)*3-2,3)"-"substr($2,7,4)","$3' infile
foo,19-Oct-2014,bar
foo2,19-Jan-2015,bar2
$
add a comment |Â
up vote
0
down vote
Another awk
approach. Uses basic awk
functionality, so likely to work with non-GNU implementations.
$ cat infile
foo,19/10/2014,bar
foo2,19/01/2015,bar2
$ awk -F, 'print $1","substr($2,0,2)"-"substr("JanFebMarAprMayJunJulAugSepOctNovDec",substr($2,4,2)*3-2,3)"-"substr($2,7,4)","$3' infile
foo,19-Oct-2014,bar
foo2,19-Jan-2015,bar2
$
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Another awk
approach. Uses basic awk
functionality, so likely to work with non-GNU implementations.
$ cat infile
foo,19/10/2014,bar
foo2,19/01/2015,bar2
$ awk -F, 'print $1","substr($2,0,2)"-"substr("JanFebMarAprMayJunJulAugSepOctNovDec",substr($2,4,2)*3-2,3)"-"substr($2,7,4)","$3' infile
foo,19-Oct-2014,bar
foo2,19-Jan-2015,bar2
$
Another awk
approach. Uses basic awk
functionality, so likely to work with non-GNU implementations.
$ cat infile
foo,19/10/2014,bar
foo2,19/01/2015,bar2
$ awk -F, 'print $1","substr($2,0,2)"-"substr("JanFebMarAprMayJunJulAugSepOctNovDec",substr($2,4,2)*3-2,3)"-"substr($2,7,4)","$3' infile
foo,19-Oct-2014,bar
foo2,19-Jan-2015,bar2
$
answered Feb 16 at 22:07
steve
12.4k22048
12.4k22048
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f424577%2fi-have-the-date-written-in-csv-file-as-19-10-2014-i-want-it-in-the-format-19-oct%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Please post at least one line of your CSV file so that I can adjust the
awk
script below!â Ned64
Feb 16 at 10:56