Imagine you have couple of files: host1.cfg, host2.cfg, host3.cfg and you want to replace “hostname1”, “hostname2”, “hostname3” in each file at once to something like “hostname1-backup”. Here’s simple sed oneliner which will do that:
1 |
sed -ri "s/hostname([1-3])/hostname\1-backup/g" host*.cfg |