I need to append a ".dev" or a ".prd" to a machine name depending on which domain they're in. The domain can be determined in the machine name, since they all follow the same pattern: hostd(..) for dev machines and hostp(..) for production machines.
Here's an example of what I want:
=============================
| input | output |
|=============|=============|
| hostd01 | hostd01.dev |
|-------------|-------------|
| hostp03 | hostp03.prd |
=============================
I'm new to sed, so I don't know how elegant is the solution I found (below). Isn't there a way to do it in one line?
sed -e 's/\([dp]\)\(..\)/\1\2.\1/'
-e 's/d$/dev/'
-e 's/p$/prd/'