Skip to main content
2 of 4
added 525 characters in body
chaos
  • 49.3k
  • 11
  • 127
  • 147

You could use sed:

sed "s/yyyymmdd/$(date '+%Y%m%d')/g" abc.fil

That replaces the string yyyymmdd with the current date formatted as desired.

Edit:

If yyyymmdd is just the format of the date you want to replace the use that command:

sed -r "s/[1,2]{1}[0-9]{3}[0,1]{1}[0-9]{1}[0,1]{1}[0-9]{1}/$(date '+%Y%m%d')/g" abc.fil

The long regular expression pattern means the following: The first digit can be 0 or 1 ([1,2]{1}), the next three can be everything from 0 to 9 ([0-9]{3}), that's the year. Now the month: the first digit can be 0 or 1 and the second can be everything from 0 to 9 ([0,1]{1}[0-9]{1}). And at last the same with the day.

chaos
  • 49.3k
  • 11
  • 127
  • 147