Use awk to format date field
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing âÂÂMonthâ with the current month name (three-letter abbreviation) and âÂÂYearâ with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".
text-processing awk
 |Â
show 3 more comments
up vote
-1
down vote
favorite
How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing âÂÂMonthâ with the current month name (three-letter abbreviation) and âÂÂYearâ with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".
text-processing awk
Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
â ilkkachu
Jul 10 at 18:43
@ilkkachu No July 2018 is not a constant.
â fball4life36
Jul 10 at 18:46
you want current month and year to be inserted?
â SivaPrasath
Jul 10 at 18:52
@sivaPrasath Yes.
â fball4life36
Jul 10 at 19:05
1
Why does it have to beawk
?
â roaima
Jul 10 at 19:53
 |Â
show 3 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing âÂÂMonthâ with the current month name (three-letter abbreviation) and âÂÂYearâ with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".
text-processing awk
How to do I convert date format from "09-12:36:10" into "09-Month-Year 12:36:10", replacing âÂÂMonthâ with the current month name (three-letter abbreviation) and âÂÂYearâ with the current year (four-digit), using awk?
For example, change "09-12:36:10" to "09-JUL-2018 12:36:10".
text-processing awk
edited Jul 11 at 4:47
G-Man
11.4k82656
11.4k82656
asked Jul 10 at 18:27
fball4life36
347
347
Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
â ilkkachu
Jul 10 at 18:43
@ilkkachu No July 2018 is not a constant.
â fball4life36
Jul 10 at 18:46
you want current month and year to be inserted?
â SivaPrasath
Jul 10 at 18:52
@sivaPrasath Yes.
â fball4life36
Jul 10 at 19:05
1
Why does it have to beawk
?
â roaima
Jul 10 at 19:53
 |Â
show 3 more comments
Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
â ilkkachu
Jul 10 at 18:43
@ilkkachu No July 2018 is not a constant.
â fball4life36
Jul 10 at 18:46
you want current month and year to be inserted?
â SivaPrasath
Jul 10 at 18:52
@sivaPrasath Yes.
â fball4life36
Jul 10 at 19:05
1
Why does it have to beawk
?
â roaima
Jul 10 at 19:53
Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
â ilkkachu
Jul 10 at 18:43
Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
â ilkkachu
Jul 10 at 18:43
@ilkkachu No July 2018 is not a constant.
â fball4life36
Jul 10 at 18:46
@ilkkachu No July 2018 is not a constant.
â fball4life36
Jul 10 at 18:46
you want current month and year to be inserted?
â SivaPrasath
Jul 10 at 18:52
you want current month and year to be inserted?
â SivaPrasath
Jul 10 at 18:52
@sivaPrasath Yes.
â fball4life36
Jul 10 at 19:05
@sivaPrasath Yes.
â fball4life36
Jul 10 at 19:05
1
1
Why does it have to be
awk
?â roaima
Jul 10 at 19:53
Why does it have to be
awk
?â roaima
Jul 10 at 19:53
 |Â
show 3 more comments
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
simply,
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'
If you are keen to have month in upper case:
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'
add a comment |Â
up vote
1
down vote
Not sure how robust you are needing this, but here is a start:
#!/usr/bin/awk -f
BEGIN
FS = "-"
print $1 "-MONTH-YEAR", $2
add a comment |Â
up vote
0
down vote
If you have GNU Awk (gawk
), you can use its built-in systime
and strftime
gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
Ex.
$ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
09 Jul 2018 12:36:10
If you need the abbreviated month in upper case, try %^b
e.g.
$ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
09-JUL-2018 12:36:10
interesting!! can you update the answer with desired format09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
1
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
simply,
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'
If you are keen to have month in upper case:
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'
add a comment |Â
up vote
1
down vote
accepted
simply,
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'
If you are keen to have month in upper case:
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
simply,
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'
If you are keen to have month in upper case:
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'
simply,
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print $1date$2'
If you are keen to have month in upper case:
echo 09-12:36:10 | awk -F '-' -v date="$(date +"-%b-%Y " )" ' print toupper($1date$2)'
edited Jul 10 at 19:27
answered Jul 10 at 18:48
SivaPrasath
3,68311636
3,68311636
add a comment |Â
add a comment |Â
up vote
1
down vote
Not sure how robust you are needing this, but here is a start:
#!/usr/bin/awk -f
BEGIN
FS = "-"
print $1 "-MONTH-YEAR", $2
add a comment |Â
up vote
1
down vote
Not sure how robust you are needing this, but here is a start:
#!/usr/bin/awk -f
BEGIN
FS = "-"
print $1 "-MONTH-YEAR", $2
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Not sure how robust you are needing this, but here is a start:
#!/usr/bin/awk -f
BEGIN
FS = "-"
print $1 "-MONTH-YEAR", $2
Not sure how robust you are needing this, but here is a start:
#!/usr/bin/awk -f
BEGIN
FS = "-"
print $1 "-MONTH-YEAR", $2
edited Jul 10 at 20:29
answered Jul 10 at 18:36
Steven Penny
2,30221535
2,30221535
add a comment |Â
add a comment |Â
up vote
0
down vote
If you have GNU Awk (gawk
), you can use its built-in systime
and strftime
gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
Ex.
$ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
09 Jul 2018 12:36:10
If you need the abbreviated month in upper case, try %^b
e.g.
$ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
09-JUL-2018 12:36:10
interesting!! can you update the answer with desired format09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
1
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
add a comment |Â
up vote
0
down vote
If you have GNU Awk (gawk
), you can use its built-in systime
and strftime
gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
Ex.
$ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
09 Jul 2018 12:36:10
If you need the abbreviated month in upper case, try %^b
e.g.
$ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
09-JUL-2018 12:36:10
interesting!! can you update the answer with desired format09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
1
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If you have GNU Awk (gawk
), you can use its built-in systime
and strftime
gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
Ex.
$ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
09 Jul 2018 12:36:10
If you need the abbreviated month in upper case, try %^b
e.g.
$ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
09-JUL-2018 12:36:10
If you have GNU Awk (gawk
), you can use its built-in systime
and strftime
gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
Ex.
$ echo '09-12:36:10' | gawk -F'[-]' 'print $1, strftime("%b %Y", systime()), $2'
09 Jul 2018 12:36:10
If you need the abbreviated month in upper case, try %^b
e.g.
$ echo '09-12:36:10' | awk -F'[-]' 'print $1 strftime("-%^b-%Y", systime()), $2'
09-JUL-2018 12:36:10
edited Jul 10 at 21:15
answered Jul 10 at 20:50
steeldriver
30.9k34877
30.9k34877
interesting!! can you update the answer with desired format09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
1
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
add a comment |Â
interesting!! can you update the answer with desired format09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
1
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
interesting!! can you update the answer with desired format
09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
interesting!! can you update the answer with desired format
09-JUL-2018 12:36:10
â SivaPrasath
Jul 10 at 21:10
1
1
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
@SivaPrasath done
â steeldriver
Jul 10 at 21:16
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%2f454548%2fuse-awk-to-format-date-field%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
Is the "July 2018" a constant, or should it be the current month? Does it have to be with awk?
â ilkkachu
Jul 10 at 18:43
@ilkkachu No July 2018 is not a constant.
â fball4life36
Jul 10 at 18:46
you want current month and year to be inserted?
â SivaPrasath
Jul 10 at 18:52
@sivaPrasath Yes.
â fball4life36
Jul 10 at 19:05
1
Why does it have to be
awk
?â roaima
Jul 10 at 19:53