XML value compare and replace


 
Thread Tools Search this Thread
Operating Systems Solaris XML value compare and replace
# 1  
Old 06-09-2017
XML value compare and replace

I need a way to to check if a value in a file that has this XML format is less than or equal to current system date/time. if it is I need to override it with a future date/time:

Here is the data sample:

Code:
<?xml version="1.0" encoding="UTF-8"?><PORT_REQUEST><HEADER><DDD_T>060920171655</DDD_T>

I want to check if the value for the DDD_T if it is equal or less than current date if so to replace it with a future date "mmddccyyhhmm".

What is the best way to do this ? I am not sure from where to even start !
# 2  
Old 06-09-2017
I'm afraid this looks more complex than it actually is:
Code:
awk -vFDT=$(date -d "+1day" +"%m%d%Y%H%M") -vSDT=$(date +"%Y%m%d%H%M")  '
match ($0, /<DDD_T>[^<]*<.DDD_T>/)      {TMP = substr ($0, RSTART+7, RLENGTH-15)
                                         if (SDT >= substr (TMP, 5, 4) substr (TMP, 1, 2) substr (TMP, 3, 2) substr (TMP, 9, 4)) \
                                         sub (TMP, FDT)
                                        }
1
' file
<?xml version="1.0" encoding="UTF-8"?><PORT_REQUEST><HEADER><DDD_T>061020172129</DDD_T>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to replace XML TAG

As per the requirement I need to replace XML tag with old to new on one of the XML file. Old<com : DEM>PHI</com : DEM> New<com : DEM>PHM</com : DEM> Please someone provide the sed command to replace above mentioned old XML tag with new XML tag (2 Replies)
Discussion started by: siva83
2 Replies

2. Shell Programming and Scripting

Compare two unsorted unequal files extracted from xml

I have two files for comparison which are extracts from set of xml files. file1 has: Comparing File: BRCSH1to320140224CC3.xml :: TZZZ:BR :: TAZZ:OUT UIZZ:0 :: ERAZ:1.000000 UIZZ:0 :: CTZZ:B UIZZ:0 :: CCAZ:MYR Comparing File: BRMY20140224CC18REG013SPFNSY13.xml :: TZZZ:BR :: TAZZ:INB... (1 Reply)
Discussion started by: vamsi gunda
1 Replies

3. Shell Programming and Scripting

Compare two xml files

Hi, I want to comapre two xml files in unix. 1st xml file contents <application> abc </application> <type>2</type> <type1>3</type1> 2nd xml file contents. <application> abc</application> <type>2</type> <type1>1</type1> <type2>567</type2> Desired output Differences in 1st file... (2 Replies)
Discussion started by: DeepaT
2 Replies

4. Shell Programming and Scripting

Find and replace from an XML

Input-xml <weblogic-web-app> <session-descriptor> <session-param> <param-name>SysName</param-name> <param-value>smilyface</param-value> </session-param> <session-param> <param-name>InternetProtocol</param-name> <param-value>xxxxxxxx</param-value> ... (2 Replies)
Discussion started by: linuxadmin
2 Replies

5. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

6. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

7. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

8. Shell Programming and Scripting

Help with find and replace in XML

Hello Guys, I have this requirement with several hundred files. I have this first set of xml's files with the following tags spread across the file FILE in SET A <Name>Lion</Name> <Age>15</Age> ..... .... ... <Date>2009-12-12</Date> Now i have this another set of files which... (5 Replies)
Discussion started by: aixjadoo
5 Replies

9. Web Development

Replace xml values

Hallo all, I try to create a bash script but till now without any positiv results. The script should replace different variables in a text file with the right xml values Look at the following xml file: file.xml =================================== <?xml version="1.0"... (1 Reply)
Discussion started by: research3
1 Replies

10. UNIX for Dummies Questions & Answers

find and replace in XML

Hi I need one clarication.. I have an xml having many entries like this.. <Cust_Name>Tom Cruise</Cust_Name> I want to rename this to <Cust_Name>TEST</Cust_Name> Pls let me know how to do it.. I was trying some basic commands like grep 'Cust_Name' * | tr '>' ',' | tr '<' ... (2 Replies)
Discussion started by: wip_vasikaran
2 Replies
Login or Register to Ask a Question