Manipulate XML File Continous STRING by each Order Line using SHELL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulate XML File Continous STRING by each Order Line using SHELL
# 1  
Old 08-08-2013
Manipulate XML File Continous STRING by each Order Line using SHELL

heres sample File:
Code:
<?xml version="1.0"?>
<!DOCTYPE cXML SYSTEM "www"><cXML..............................................
<OrderRequest>USE UNIX.com</Extrinsic><Extrinsic name="UniqueName">Peter@UNIX.com</Extrinsic><Extrinsic name="ContractingEntity">UNIX AMERICA</Extrinsic></OrderRequestHeader><ItemOut lineNumber="1" quantity="1" ....</ItemOut><ItemOut lineNumber="2" quantity="1" ......<Comments>UNIX IS GREAT</Comments></ItemOut><ItemOut lineNumber="3"......</Comments></ItemOut></OrderRequest></Request></cXML>

how I want it:
Code:
<?xml version="1.0"?>
<!DOCTYPE cXML SYSTEM "www"><cXML..............................................
USE UNIX.com</Extrinsic><Extrinsic name="UniqueName">Peter@UNIX.com</Extrinsic><Extrinsic name="ContractingEntity">UNIX AMERICA</Extrinsic></OrderRequestHeader>
<ItemOut lineNumber="1" quantity="1" ..................................</ItemOut>
<ItemOut lineNumber="2" quantity="2" ......<Comments>UNIX IS GREAT</Comments></ItemOut>
<ItemOut lineNumber="3".....................................</Comments></ItemOut>
</OrderRequest></Request></cXML>

what I use:

Code:
 
sed -i $file -e 's/<\/ItemOut>/&\n/g;'

problems:

1)This do not bring linenumber 1 to new line
2)Larger files behave weird, (but there is a pattern, every 10 lines tags go into diffent line, there is a big space every 10 lines) (IF the file is LARGE)
3)Every <ItemOut lineNumber=".... should be a new line and end with </ItemOut> (As per BLUE above)
4) OPEN TAG <ItemOut and CLOSED TAG </ItemOut> always exists EXISTS in the file
5) There are Multiple XML files and I loop through each file using $i as in the code above..

Thanks
pete

Last edited by Scott; 08-08-2013 at 01:54 PM.. Reason: More code tags
# 2  
Old 08-08-2013
One way.., assume x.xml has the contents...you have to quote the end of line and hit return key, then on next line close the sed expression
Code:
 cat x.xml | sed -e 's/<\/ItemOut>/ \    
/g'

# 3  
Old 08-08-2013
Or using awk:
Code:
awk '{gsub("</ItemOut>","&"RS)}1' file.xml

# 4  
Old 08-08-2013
This is working BUT when I have a LARGE file it behaves weird

the tags are not proper in a pattern meaning

it follows pattern for 10 lines then RANDOMLY another tag gets cut off then there is a space THEN it works fine again the PATTTERN Repeats

Code:
 
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ............................<sometag>

............</ItemOut>
*****SPACE*****SPACE****HERE***
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ............................<sometag>
............</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
 <ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
 
*****SPACE*****SPACE****HERE***
 
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
 <ItemOUT ........................................</ItemOut>
<ItemOUT ............................<sometag>
............</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>
<ItemOUT ........................................</ItemOut>


it does this for LARGE files dont know why? when I use any of sed and awk commands above

For Smaller files with 20-30 lines its ok , but with larger files it does not work..

Any advices please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to manipulate string in line?

Hello, I looked up on google but do not know from which point to start... I am under ubuntu 18 bionic and Mainfile consists of 25K lines MainFile: Test,AAEE9FED3, GGBBDD DD AA X2d Moscow 112233445566aaBBccPPdddEE Test,AAEE9FED3, GG33DD s00022 Leningrad 11298932566aaBBccPPdddEE... (8 Replies)
Discussion started by: baris35
8 Replies

2. Shell Programming and Scripting

Extract & Manipulate continous data stream-- tcpdump

Hello; I have this rather tricky problem to solve --(to me, anyways) .. I am processing the following one liner with tcpdump.. tcpdump -i T3501 -A ether host 00:1e:49:29:fc:c9 or ether host 00:1b:2b:86:ec:1b or ether host 00:21:1c:98:a4:08 and net 149.83.6.0/24 | grep --line-buffered -B... (5 Replies)
Discussion started by: delphys
5 Replies

3. Shell Programming and Scripting

Find string in one file and manipulate other

hi, I have 2 files delimited by "|" File 1: 1|28|ABC|11|9620034||XXX555| 29|22|ABC|11|9620258||XXX555| 51|26|ABC|11|9620314||XXX555| 77|20|ABC|11|9630506||XXX555| 97|36|ABC|11|9630562||XXX555| File 2: 9620028|I 9620034|I 9620314|S 9620332|I 9620258|I 9630506|S 9630562|S (3 Replies)
Discussion started by: pparthiv
3 Replies

4. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

5. Shell Programming and Scripting

Manipulate string in shell script

I am writing a shell script for some purpose. I have a variable of the form -- var1 = "policy=set policy" Now I need to manipulate the variable var to get the string after index =. that is i should have "set polcy". Also I need to to this for many other variables where the value of "=" is not... (3 Replies)
Discussion started by: Dev_Sharma987
3 Replies

6. Shell Programming and Scripting

Shell script to manipulate a file

Hello, I have a file with following contents : WSL SRVGRP=LISTENER SRVID=2 CLOPT="-A -t -- -n 0x0002aa050a03cc65 " RQPERM=0660 REPLYQ=Y RPPERM=0660 MIN=1 MAX=1 CONV=N I need to print only the value in Hex i.e.... (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

7. Shell Programming and Scripting

Extract File line and manipulate

How can I print a section of each line in a text file. Eg CODE1 XYR Test2 10319389 CODE2 XYR Test2 10319389 CODE3 XYR Test2 10319389 CODE4 XYR Test2 10319389 CODE5 XYR Test2 10319389 First thing that would be nice would a new file like, awk sed and substring may help but can't figure it... (6 Replies)
Discussion started by: kelseyh
6 Replies

8. Shell Programming and Scripting

How to manipulate first column and reverse the line order in third and fourth column?

How to manipulate first column and reverse the line order in third and fourth column as follws? For example i have a original file like this: file1 0.00000000E+000 -1.17555359E-001 0.00000000E+000 2.00000000E-002 -1.17555359E-001 0.00000000E+000 ... (1 Reply)
Discussion started by: Max Well
1 Replies

9. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

10. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies
Login or Register to Ask a Question