1

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/'
2
  • what is the actual input format? Is it the table above? Commented Sep 30, 2011 at 22:37
  • No the actual input are the columns inside the table "hostd01" and "hostp03" Commented Sep 30, 2011 at 22:40

1 Answer 1

2
$ sed '/d/{s/$/\.dev/} ; /p/{s/$/\.prv/}' input 
hostd01.dev
hostp03.prv
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.