SED Question

Posted on 2002-06-27
Last Modified: 2013-11-18
I need to SED a file and replace:

   Transport Hostname="cscx1001"


   Transport Hostname=""

Here is the whole command:

cat plugin-cfg.xml | sed "s/Transport Hostname="cscx1234"/Transport Hostname=""/g" > plugin.xml

I'm having issues due to the "'s around "cscx1234" and ""

I tried escaping the " with slash, but that didn't work.

After I get the syntax to make this work from the command line I have to take it one step further....

I will be placing "cscx1234" and "" in variables - HOSTNAME and IP.  If the double quotes were not an issue it would look something like this:

cat ${CONFIG}/plugin-cfg.xml | sed "s/Transport Hostname="${HOSTNAME}"/Transport Hostname="${IP}"/g" > ${CONFIG}/plugin.xml

Any ideas on the correct syntax for these strings?



Question by:lphillips120898
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 84

Expert Comment

ID: 7114276
cat plugin-cfg.xml | sed 's/Transport Hostname="cscx1234"/Transport Hostname=""/g' > plugin.xml
LVL 84

Expert Comment

ID: 7114288
cat ${CONFIG}/plugin-cfg.xml | sed 's/Transport Hostname="'${HOSTNAME}'"/Transport Hostname="'${IP}'"/g' > ${CONFIG}/plugin.xml

Author Comment

ID: 7114993

The first statement worked like a charm at the command line, so I assumed the second statement would work as well within the script - but it didn't.

Will you take a look at the script and see if you find anything wrong?  I echoed the HOSTNAME and IP, so I know they are gettting set.  Let me know what you think.



*** SCRIPT ***
[wsadmin @ cscx1001:/opt/WebSphere/AppServer/bin/scripts]:> more
DT=$(date +%d-%m-%y)
HOSTNAME=`uname -n`
BOOTSTRAP=$(grep bootstrapPort ${BIN}/admin.config | awk -F'=' '{print $2}')
IP=`ping -c 1 $HOSTNAME | sed "s/)/(/g" | awk '{FS="("}{print $2}'`

echo $IP

${BIN}/ -adminNodeName $HOSTNAME -nameServiceHost $HOSTNAME -nameServicePort $BOOTSTRAP

cat ${CONFIG}/plugin-cfg.xml | sed 's/Transport Hostname="${HOSTNAME}"/Transport Hostname="${IP}"/g'
 > ${CONFIG}/plugin.xml

** OUTPUT ** The "plugin.xml" doesn't have any changes - it is the same as plugin-cfg.xml  ***

cscx1001  (echo of HOSTNAME)  (echo of IP)

/WebSphere/AppServer/config]:> ls -lat plugin*
-rw-r--r--   1 wsadmin  wsadmin        3943 Jun 27 16:00 plugin.xml
-rwxr-----   1 wsadmin  wsadmin        3943 Jun 27 16:00 plugin-cfg.xml

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

LVL 84

Accepted Solution

ozo earned 100 total points
ID: 7115274
You left out the ' between the end of
's/Transport Hostname="
also the 's around
"/Transport Hostname="
and before
LVL 51

Expert Comment

ID: 7115842
# ozo's working suggestion improved:
(cat ${CONFIG}/plugin-cfg.xml)|sed 's/Transport Hostname="'${HOSTNAME}'"/Transport Hostname="'${IP}'"/g' > ${CONFIG}/plugin.xml

Author Comment

ID: 7116183
Worked like a charm!  Thanks.

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. Please see for the updated article. It is avail…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question