lphillips120898
asked on
SED Question
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"/Transp ort 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}"/Tra nsport Hostname="${IP}"/g" > ${CONFIG}/plugin.xml
Any ideas on the correct syntax for these strings?
Thanks,
Lisa
Transport Hostname="cscx1001"
with:
Transport Hostname="9.9.9.9"
Here is the whole command:
cat plugin-cfg.xml | sed "s/Transport Hostname="cscx1234"/Transp
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}"/Tra
Any ideas on the correct syntax for these strings?
Thanks,
Lisa
cat plugin-cfg.xml | sed 's/Transport Hostname="cscx1234"/Transp ort Hostname="10.9.9.9"/g' > plugin.xml
cat ${CONFIG}/plugin-cfg.xml | sed 's/Transport Hostname="'${HOSTNAME}'"/T ransport Hostname="'${IP}'"/g' > ${CONFIG}/plugin.xml
ASKER
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/Ap pServer/bi n/scripts] :> more genPlugin.sh
DT=$(date +%d-%m-%y)
BACKUP=/local/WebSphere/ap ps/Backup
HOSTNAME=`uname -n`
BIN=/opt/WebSphere/AppServ er/bin
CONFIG=/opt/WebSphere/AppS erver/conf ig
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}"/Tra nsport 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/confi g]:> 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
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/Ap
DT=$(date +%d-%m-%y)
BACKUP=/local/WebSphere/ap
HOSTNAME=`uname -n`
BIN=/opt/WebSphere/AppServ
CONFIG=/opt/WebSphere/AppS
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}"/Tra
> ${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/confi
-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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
# ozo's working suggestion improved:
(cat ${CONFIG}/plugin-cfg.xml)| sed 's/Transport Hostname="'${HOSTNAME}'"/T ransport Hostname="'${IP}'"/g' > ${CONFIG}/plugin.xml
(cat ${CONFIG}/plugin-cfg.xml)|
ASKER
Worked like a charm! Thanks.