I have got a file that has 24-jan-2017 for example. I want to increment the given date by 1 year and print.

Any clue how to do that via cli?


  • Do you need to do this from command line or in a text editor?
    – ProdIssue
    May 14, 2018 at 16:18
  • command line...
    – Jacky
    May 14, 2018 at 16:19
  • In this file, is the date on a line by itself, or do we need to extract from the rest of the line? May 14, 2018 at 16:29

1 Answer 1

awk -F- -vOFS=- 'NF==3 {++$3};{print}' < file

Would increment the third field (- separated fields) on each line of file that have 3 fields.

  • Might break in a few million years when the integer can't be incremented any further.
    – DopeGhoti
    May 14, 2018 at 18:27

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.