Machines at work follow a constant naming pattern:
where [domain] is either "d" for dev machines and "p" for production machines, and [id] is a 2-digit string that is different for each machine. For example: 'hostp_a1' or 'hostd_g5'.
Now due to new company policies, we have separated the two domains and we have to append a suffix ".dev" for dev machines and ".prd" for production ones. My previous machines are now called 'hostp_a1.prd' and 'hostd_g5.dev'
I don't want to change my old habits, so I am wondering if there's a way for Ksh to do this for me dynamically. Here's a sed script that would do it for me:
sed -e 's/host\([dp]\)_\(..\)/host\1_\2.\1/' -e 's/p$/prd/' -e 's/d$/dev/'
Here are some solutions I thought of:
If I could do something like
The trigger would execute the sed each time a command is entered. Might hurt performance a bit, but I don't care since it's only interactive.
Is there any way Ksh could do that? It probably doesn't help that I'm using an old version
Version M-11/16/88i. Can maybe other shells do this?
(as long as we're at it, I'm currently learning
sed so if anyone has a better sed command to suggest, please do. Thanks).