0

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 ?

2
  • Your variable is variable in shell script or in awk?
    – cuonglm
    Jul 7, 2014 at 9:30
  • it's in awk file Jul 7, 2014 at 9:31

1 Answer 1

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .