I have date in format YYYY-MM-DD in variable 'a'. I want to convert it in format YYYYMMDD and store in variable 'b'. The variable is in an awk variable.
How can I do the same ?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI have date in format YYYY-MM-DD in variable 'a'. I want to convert it in format YYYYMMDD and store in variable 'b'. The variable is in an awk variable.
How can I do the same ?
Use gsub
:
a="YYYY-MM-DD"
b=a
gsub("-", "", b)
print(b)
will output:
YYYYMMDD
gsub
replaces the first argument with the second in the third, in-place, so we copy the value of a
into b
first. We replace the -
characters with nothing.