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 ?

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

Use gsub:

gsub("-", "", b)

will output:


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.