Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy script needs to update an integer in a config file

I'm working on a python fabric script that eases my solution deployment on different environments.

It works great so far, but I have at the end of the script a prompt that ask me if I want to edit a .yml config file, basically, to update my assets version. I go manually through vim inside and basically increment that number:

  reconnection_delay: 50
  max_attempts: 500
  assets_version: 5360

How could I possibly automatically do that only with command line. Should use sed or perl it seems, but I'm not familiar with that, and some help might be appreciated here!

Thanks

like image 873
guillaumepotier Avatar asked Jun 03 '26 19:06

guillaumepotier


1 Answers

perl -i.backup -pe 's{ ( \b assets_version: \s+ ) (\d+) $ }{ $1 . ( 1 + $2 ) }xmse;' your.yml

This will make a copy of your.yml named your.yml.backup, look for the line containing "assets_version:" and increment the number by 1.

like image 50
Perleone Avatar answered Jun 07 '26 10:06

Perleone