Machines at work follow a constant naming pattern:
host[domain]_[id]
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:
Regex alias:
If I could do something like
alias host[dp]_..='.....Triggers:
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).
hostd_g5to be systematically rewritten tohostd_g5.devwherever you type it? Even if you typedls notes/hostd_g5.txt? Or are you interested in specific network-related commands? Or do you want that whenever the string is looked up in DNS? – Gilles Sep 30 '11 at 23:29