Change variable value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Change variable value
# 1  
Old 11-05-2013
Change variable value

I have big XML which i want to change all VERSIONNUMBER equal to 1,in existing file values of VERSIONNUMBER will be different as below now i want to change all VERSIONNUMBER values qual to 1.Please help me which will convert versionnumber values.
Code:
<SHORTCUT  OBJECTSUBTYPE ="" OBJECTTYPE  VERSIONNUMBER ="2"/>
< OBJECTTYPE REPOSITORYNAME ="" VERSIONNUMBER ="4"/>
REFERENCETYPE ="LOCAL"  VERSIONNUMBER ="1"/>
REFERENCETYPE ="LOCAL"  VERSIONNUMBER ="2"/>
<CONFIG DESCRIPTION ="Default VERSIONNUMBER ="1">

OUTPUT:
Code:
 
<SHORTCUT  OBJECTSUBTYPE ="" OBJECTTYPE  VERSIONNUMBER ="1"/>
< OBJECTTYPE REPOSITORYNAME ="" VERSIONNUMBER ="1"/>
REFERENCETYPE ="LOCAL"  VERSIONNUMBER ="1"/>
REFERENCETYPE ="LOCAL"  VERSIONNUMBER ="1"/>
<CONFIG DESCRIPTION ="Default VERSIONNUMBER ="1">

Moderator's Comments:
Mod Comment Next time use code tags please!
# 2  
Old 11-05-2013
So, you just want to change
Code:
VERSIONNUMBER ="2"

to
Code:
VERSIONNUMBER ="1"

throughout the entire file?
# 3  
Old 11-05-2013
Since no script was given, moved to dummies...
# 4  
Old 11-05-2013
yes,it should change complete file.in file it may be any value for versionnumber but command/script should change all values to one.
# 5  
Old 11-05-2013
Hello,

Could you please try the following code. Let's say change_number is the file which have input data.


Code:
awk -vs1="VERSIONNUMBER ="1"" '/VERSIONNUMBER =/ gsub(/VERSIONNUMBER ="2"/,s1)' change_number


Output will be as follows.

Code:
<SHORTCUT  OBJECTSUBTYPE ="" OBJECTTYPE  VERSIONNUMBER =1/>
< OBJECTTYPE REPOSITORYNAME ="" VERSIONNUMBER ="4"/>
REFERENCETYPE ="LOCAL"  VERSIONNUMBER ="1"/>
REFERENCETYPE ="LOCAL"  VERSIONNUMBER =1/>
<CONFIG DESCRIPTION ="Default VERSIONNUMBER ="1">


Thanks,
R. Singh
# 6  
Old 11-05-2013
Code:
$ sed 's/VERSIONNUMBER[ ]*="[^"]*"/VERSIONNUMBER ="1"/g' file.xml > newfile.xml

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Change Date in Variable

I am hoping someone can help me with this issue. I am extracting a date from a file that is in DD/MM/YYYY format using... expiry_date=`echo ${line}| awk -F, '{ print $4 }' | tr -d '\r'` What I need to do is amend the value so instead of getting 30/12/2016 I end up with 12/30/2016. I have... (11 Replies)
Discussion started by: theref
11 Replies

2. Shell Programming and Scripting

Change the value of variable in a file

Hi Friends, I have shell script file1.sh which has reference to enviornment file called Content of filenev.sh SKIP_FLAG=N ORACLE_HOME=/u01/oracle/database My requirement is to change the value of SKIP_FLAG to Y in filenv.sh from file1.sh. Could anyone please help me to do... (2 Replies)
Discussion started by: vfrg
2 Replies

3. Shell Programming and Scripting

I can't change the value of my variable!

I made this HEADMAKER variable to pull the header from the first file in the loop, but then to stop so it doesn't override the file with later loops. However, I CANNOT get it to reassign the value of my variable away from "FIRST". I have also tried it with 1 and 0, and with and without quotes and... (3 Replies)
Discussion started by: crankymonkey
3 Replies

4. Shell Programming and Scripting

Change Variable Value from Multiple Scripts and Use these Variable

Hi to All, Please find below details. file_config.config export file1_status="SUCCESS" export file2_status="SUCCESS" file_one.sh I am calling another two shell script from these script. I need to pass individual two script status (If it's "FAILED") to file_main.sh. file_main.sh I... (2 Replies)
Discussion started by: div_Neev
2 Replies

5. Shell Programming and Scripting

Change the filename variable value

Hi guys, I have a variable where i am storing the filename (with full path). I just need the value before ".txt". But instead of getting the filename i am getting the contents of the filename. FileName=/appl/data/Input/US/Test.txt a=`awk -F"." '{print $1}' ${FileName}` echo $a... (3 Replies)
Discussion started by: mac4rfree
3 Replies

6. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

7. Shell Programming and Scripting

How do I change a variable to something only if it's empty?

I feel like it is just a matter of using the $ operators correctly, but I can't seem to get it... hostname="network" ip="192.168.1.1" netmask="" variables=( $hostname $ip $netmask ) for var in ${variables} do if ; then $var="--" fi done echo... (7 Replies)
Discussion started by: etranman1
7 Replies

8. Shell Programming and Scripting

Change only the name of a variable

if I have a variable named z inside a java file, is there any way to globally change the name of the variable and all its occurences as a variable? (but not any other z that is not part of that variable name) (3 Replies)
Discussion started by: lydiaflamp
3 Replies

9. Shell Programming and Scripting

Variable name change in a loop

I need to do something like this:for I in var1 var2 var3 ; do $I = "Something calculated inside the loop" doneObviously it doesn't work...but is it possible doing that in other ways? Thanks in advance. (6 Replies)
Discussion started by: canduc17
6 Replies

10. Shell Programming and Scripting

how to change the variable in the file

Hi all, I have problem regarding how to change the quantity in the file. I will explain you by an example. I have one file whose name is sample. The content of file are as follows: sample ----------------------------------------------------------- 1 334 3562 2345 5324 85657 75666 845 ... (0 Replies)
Discussion started by: Aniket
0 Replies
Login or Register to Ask a Question