Script is showing abnormal behavior...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script is showing abnormal behavior...
# 1  
Old 09-23-2009
Question Script is showing abnormal behavior...

Hi,

facing unusual problem, below are 2 same scripts, one is working and other is not. please help

--- THIS SCRIPT IS WORKING FINE!!!!
#! /bin/sh
phone=`grep "<phone>" data.xml | sed 's:<phone>::;s:</phone>::'`
echo "Phone Number is:"$phone
repnum=554156
cat data.xml | sed -e s/$phone/$repnum/ > newdata.xml


Input File:
data.xml:
<Name>ABCDEF</Name>
<phone>748347</phone>



Output file:
newdata.xml:
<Name>ABCDEF</Name>
<phone>554156</phone>





------THIS IS NOT ABLE TO REPLACE THE VALUE OF THE TAG "PolNumber"
#! /bin/sh
polnum=`grep "<PolNumber>" adi.xml | sed 's:<PolNumber>::;s:</PolNumber>::'`
echo "PolNumber is:"$polnum
newpol=101101
cat adi.xml | sed -e s/$polnum/$newpol/ > tmpadi.xml



Input file:

>cat adi.xml

<Policy id="Policy_1">
<PolNumber>109301793</PolNumber>
</Policy>

OutPut: is Same. File is not being updated with the new value..

Any clues?

Thanks in advance.
# 2  
Old 09-23-2009
Code:
# cat data.xml
<?xml version="1.0"?>
<xml>
        <Name>ABCDEF</Name>
        <phone>748347</phone>
</xml>

# xml ed -P -u "//phone" -v "554156" data.xml > newdata.xml

# cat newdata.xml
<?xml version="1.0"?>
<xml>
        <Name>ABCDEF</Name>
        <phone>554156</phone>
</xml>

See: XmlStarlet Command Line XML Toolkit User's Guide
# 3  
Old 09-23-2009
Quote:
Originally Posted by Prateek007
...
OutPut: is Same. File is not being updated with the new value...
Working fine here

$more tmpadi.xml
<Policy id="Policy_1">
<PolNumber>101101</PolNumber>
</Policy>
# 4  
Old 09-23-2009
The scripts are equivalent and should give the same output. I ran the second one and the output is
Code:
cat tmpadi.xml
<Policy id="Policy_1">
<PolNumber>101101</PolNumber>
</Policy>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script unusual behavior

Hello, I have noticed some unusual behavior while running the script. when i use below script it gives output 355.23 #!/bin/bash ONEDAY=`date +%Y%m%d --date="1 days ago"` cat /opt/occ/var/performance/counters_`date -d "1 day ago" +%Y%m%d`*|grep "Gy,Gy-Gy-CCR"|awk -F"," '{print... (5 Replies)
Discussion started by: scriptor
5 Replies

2. Shell Programming and Scripting

Script showing incorrect output

Hello scripting geeks, I am new to scripting and facing some issues in writing the logic of the script. Request your kind help here Actually when i run a command i get o/p as below o/p : 0x0000 0x0000 0x0000 0x0000 0x0000 0x0000 these are hex values i guess...now i want to... (15 Replies)
Discussion started by: kulvant29
15 Replies

3. Shell Programming and Scripting

shell script behavior is strange or I'm not understanding

Hi I have wrote the small script, where $SRC=$HOME the input file is simple text file having directories in my $SRC on pre line desktop download myfiles games #!/bin/bash FILENAME=$1 ERROR_LOG="$SRC/err.$$.log" while read line do echo "########## strat Gmake $line... (6 Replies)
Discussion started by: the.reverser
6 Replies

4. Shell Programming and Scripting

bash script for showing last users

Hi! I'm new in scripting and I need some help with one simple script. I have to write a program that shows in a predetermined period (using "last" command), to draw up a list of users who have used the machine during this period. Each user to indicate how many sessions it has been during this... (9 Replies)
Discussion started by: vassu
9 Replies

5. Shell Programming and Scripting

Showing off my rsync-to-USB script

Thank you all for helping me figure out how to manage spaces in paths. The following script is the result. The script uses rsync to backup files to a USB device. Special thanks to Scrutinizer:b:. rsync2u is a free menu-driven script. Down load the script from... (7 Replies)
Discussion started by: wolfv
7 Replies

6. Shell Programming and Scripting

Behavior of Bad Script in Cron Job

Hi A Ksh script is deployed in a server and executed through cronjob. If one of the line in the middle of the script fails . Are the remaining lines executed ? (3 Replies)
Discussion started by: Sivaswami
3 Replies

7. Solaris

RC script behavior within Zones

Is there a difference in behavior with start up scripts that are inside of local zones, were trying to write some startup scripts, and it appears things are not running the same, and in some cases, it appears that rc sctripts are not running at all. Anyone else run into this? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

8. UNIX for Dummies Questions & Answers

Weird Behavior of a Script

ok, there's a script i'm working on written in shell programming. #!/bin/sh this script is written to spit out the contents of certain variables inside of it so the output looks something like this: server01=89 server02=69 server03=89 server04=76 now, when i run this script from the... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Dummies Questions & Answers

Odd .sh behavior in script

Hello, I have been working on a what I thought was a fairly simple script for installing a software kit on Linux and Unix I am not new to scripting but am far from being fluent in sh scripting. any assistance would be appreciated. I have an odd bug occuring when executing the script. When... (2 Replies)
Discussion started by: robertmcol
2 Replies

10. Shell Programming and Scripting

executing script not showing up in ps -efx

Hi everyone, here's my problem. I have a script that runs in a infinite loop, repeating the same action in another script every 10 minutes. We need to monitor whether or not this loop script is running and be able to kill it should the need arise. However, the name of the script does not show up... (6 Replies)
Discussion started by: herman404
6 Replies
Login or Register to Ask a Question