Sponsored Content
Top Forums Shell Programming and Scripting Replacing tab value in xml file Post 302931627 by krsnadasa on Thursday 15th of January 2015 07:32:41 AM
Old 01-15-2015
Hi RudiC

This works great the way you defined. But when I do little different as you have advised me in earlier post it does not work -
What I did is kept all search patterns in another file -

mypattern.txt -
Code:
TTY_DAPP_OSL_KEYSTORE_MYWORD
TTY_SNO_SPNEGO_MYWORD
IIT_DAPP_BIND_MYWORD
keystoremyPass
myword

Code:
nawk 'BEGIN{FS="\"" ;OFS="\""} NR==FNR{Err[$1]++;next}
{split($1,myarr," ")}
myarr[1] in Err {$2="---"}; $2 in Err { $4="---"}}1' mypattern.txt  file

OutPut -
Code:
                               keystoremyPass="xxx" />
                               myword="xxx"
<Environment name="TTY_DAPP_OSL_KEYSTORE_MYWORD" value="---" type="java.lang.String"/>
<Environment name="TTY_SNO_SPNEGO_MYWORD" value="---" type="java.lang.String"/>
<Environment name="IIT_DAPP_BIND_MYWORD" value="---" type="java.lang.String"/>

This proves that array
Code:
myarr[1]

have all the patterns stored there.
even if I use
Code:
sub

function in place of
Code:
split

as you did still same output comes. Any idea?

Thanks

---------- Post updated 01-15-15 at 07:32 AM ---------- Previous update was 01-14-15 at 07:57 AM ----------

Hello RudiC

My bad. I was doing minor mistake. In mypattern file I am missing
Code:
=

for
Code:
 keystoremyPass,myword

.
It should be like that -
Code:
TTY_DAPP_OSL_KEYSTORE_MYWORD
TTY_SNO_SPNEGO_MYWORD
IIT_DAPP_BIND_MYWORD
keystoremyPass=
myword=

Really Thank you and Ravi for all along help. Great learning thanks guys!!

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing string in an XML file

Hi all, I need to replace string in XML file..XML file like <dependency> <groupId>fr.orange.portail.ear</groupId> <artifactId>_AdminServicesEAR</artifactId> <version>1.0.0-20080521.085352-1</version> <type>ear</type> </dependency> <dependency> ... (2 Replies)
Discussion started by: subin_bala
2 Replies

2. UNIX for Dummies Questions & Answers

Replacing Comma by Tab

Hi All, i have a file test.txt as shown below, 1,test,test111 2,rest,rest222 i want to replace the commas by tab delimiter.., it should be like, 1 test test111 2 rest rest222 i tried the following code, sed 's/,/\\t/g' test.txt >> ouptut.txt (9 Replies)
Discussion started by: Serious Sam
9 Replies

3. Shell Programming and Scripting

Read and copy xml line by line and preserve tab?

I'm trying to read an xml file and copy it line by line to another file and want to preserve the tabs. What i'm trying to do is if I get to a certain line in the xml, I'm going to check to see if the next line is specifically what I want. If it's not, then I want to insert a single line of text... (4 Replies)
Discussion started by: DeuceLee
4 Replies

4. Shell Programming and Scripting

Replacing the last record in xml with different tags

I have special requirement, my system provided the xml file as below(available xml file) and I need to convert it as below desired xml file. is it possible thru shell scripts or awk? What I need is : my available xml contains number of records with tags <RevenueAmounts>, the last of record is... (6 Replies)
Discussion started by: LinuxLearner
6 Replies

5. Shell Programming and Scripting

Replacing number between xml tags with ksh shell script

Hallo, im basically a complete noob on shell scripting and im trying to replace or rather add 1 to a number between xml tags. The xml basically has a tag somewhere that looks like this: <tag>12345678901234</tag> Now i want to replace the number between the tags. And i want the file to... (6 Replies)
Discussion started by: Demoric
6 Replies

6. Shell Programming and Scripting

Replacing part of XML code inside comment tags

Hello! I'd like to modify custom values in a XML config file between comment tags using bash script. <feature> <keyboardshortcut>C-m</keyboardshortcut> <option1>disabled</option2> <option2>enabled</option2> </feature> <!-- bash script features START --> <feature> ... (2 Replies)
Discussion started by: prism1
2 Replies

7. Shell Programming and Scripting

Reading XML and replacing a string

Hi All, My thanks in advance for you guys reading this and for any posts. I'm having 100 XML files, I need script which replace a specific string. It must be incrementing in 100 xml files.. Sample XML files: <hwIPHostName type="attrib">DEMO1</hwIPHostName> I need Demo1 to be... (4 Replies)
Discussion started by: karty2129
4 Replies

8. Shell Programming and Scripting

Replacing a file in between a XML file

I am having XML file,i need to replace a range of string and replace with a file,Pls anyone help, My Xml file looks like </Order><PersonInfoShipTo AddressID="446311709" AddressLine1="" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper=""... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

9. Shell Programming and Scripting

Replacing a value in all xml's

Hi Folks, Could you please advise what will be the unix command to replace the character in all xml's under a particular directory for example let say I rite now at the following below location $ cd /opt/apr/rt/conf now under conf there are so many xml's and in those xml's i want to... (2 Replies)
Discussion started by: punpun66
2 Replies

10. Shell Programming and Scripting

Convert tab separated text to non-trivial xml. (pwsafe --> KeePassx)

I'd like to take the output of `pwsafe --exportdb > database.txt` and convert it to a KeePassX XML friendly format (feature request in pwsafe). I found flat file converter but the syntax is beyond me with this example. Solutions are welcomed. More details Here is the pwsafe --> KeePassX XML... (2 Replies)
Discussion started by: graysky
2 Replies
All times are GMT -4. The time now is 04:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy