?
Solved

SED Question

Posted on 2002-06-27
6
Medium Priority
?
327 Views
Last Modified: 2013-11-18
I need to SED a file and replace:

   Transport Hostname="cscx1001"

with:

   Transport Hostname="9.9.9.9"

Here is the whole command:

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

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

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 "10.9.9.9" 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?

Thanks,

Lisa


0
Comment
Question by:lphillips120898
[X]
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
6 Comments
 
LVL 84

Expert Comment

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

Expert Comment

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

Author Comment

by:lphillips120898
ID: 7114993
070,

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.

Thanks,

Lisa

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

echo $HOSTNAME
echo $IP

${BIN}/GenPluginCfg.sh -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  ***

/scripts]:> genPlugin.sh
cscx1001  (echo of HOSTNAME)
10.12.90.10  (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


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 7115274
You left out the ' between the end of
's/Transport Hostname="
and
${HOSTNAME}
also the 's around
"/Transport Hostname="
and before
"/g'
0
 
LVL 51

Expert Comment

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

Author Comment

by:lphillips120898
ID: 7116183
Worked like a charm!  Thanks.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

762 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