Change XML file structure script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change XML file structure script
# 8  
Old 10-07-2011
I didn't understand the "divided by 2" reason as your statement is not clear.
Probably you want to split the final output file for being too large?

From the comments, If I understood you correctly, This is what you can do..

1) create two file which contains all the "vi files" and "ci files". The the order must be sequential. i.e "June.ci" and "June.vi" must be at the same line in both the files.
2) If you are not sure about the files i.e "June.ci" is there but "june.vi" is missing, You need to handle that condition to ignore that file. (its easy)



Code:
$ ls *vi.xml
December_vi.xml  July_vi.xml      June_vi.xml
$ 
$ ls *ci.xml
December_ci.xml  July_ci.xml      June_ci.xml
$ 
$ 
$ 
$ cat proc 
for i in *_vi.xml
do
        echo $i >> vi_file_list
        echo ${i/_vi/_ci} >> ci_file_list
done
 
 
exec 6<vi_file_list
while read -r ci
do
        read -r vi <&6
        echo Code to add first 30 fixed lines
        echo Code to add lines after processing $ci
        echo Code to add lines after processing $vi
        echo Code to add last 20 fixed lines
done <ci_file_list
exec >&6-
$ 
$ 
$ 
$ ./proc 
Code to add first 30 fixed lines
Code to add lines after processing December_ci.xml
Code to add lines after processing December_vi.xml
Code to add last 20 fixed lines
Code to add first 30 fixed lines
Code to add lines after processing July_ci.xml
Code to add lines after processing July_vi.xml
Code to add last 20 fixed lines
Code to add first 30 fixed lines
Code to add lines after processing June_ci.xml
Code to add lines after processing June_vi.xml
Code to add last 20 fixed lines
$ 
$

# 9  
Old 10-09-2011
Hi anchal_khare,

I can see it works, many thanks, only I don't understand some of the syntax in your code, may you explain me please the parts in red please?

1-)
Code:
 echo ${i/_vi/_ci} # What does it mean?

2-)
Code:
exec 6<vi_file_list # What does the exec command do and 6 why?

3-)
Code:
while read -r ci # Why -r and not only r?

4-)
Code:
read -r vi <&6 # What does it mean?

5-)
Code:
exec >&6- # This is like closing the exec 6 block?, why you use "-"?

6)
Code:
./proc # I think I understand this a little bit, this is like in your first code, closign "cat" block, 
only that is like executing a script because of the "./", right?

7-) Regarding the "cat proc" block, do you know how many lines can store or how is the capacity in memory before print them?

Many thanks for your great help.

Regard.
# 10  
Old 10-10-2011
Quote:
Originally Posted by cgkmal
I don't understand some of the syntax in your code, may you explain me please the parts in red please?
Most of the part you will understand yourself if you think about it.
I will try to help you explaining and/or the source where you can get the help. (man pages are the easiest and best way offcourse).

Quote:
1-)
Code:
 echo ${i/_vi/_ci} # What does it mean?

replacing "_vi" with "_ci" in the variable "$i". ( output to STDOUT, hence redirected to file). Check for string manipulation in bash/ksh.


Quote:
2-)
Code:
exec 6<vi_file_list # What does the exec command do and 6 why?

opening the file for reading with file descriptor 6. ( you can use any number form 3 to 9. since 0,1 and 2 are the standard descriptor used for STDIN,STDOIUT and STDERR respectively.) See IO Redirection for more details

Quote:
3-)
Code:
while read -r ci # Why -r and not only r?

Its your choice. "-r" invokes the "restricted shell". man bash and search for RESTRICTED SHELL.

Quote:
4-)
Code:
read -r vi <&6 # What does it mean?

Reading input line by line from the file (which is FD 6 now ) each line is in the variable "vi".

Quote:
5-)
Code:
exec >&6- # This is like closing the exec 6 block?, why you use "-"?

Yes. syntax for closing FD.

Quote:
6)
Code:
./proc # I think I understand this a little bit, this is like in your first code, closign "cat" block, 
only that is like executing a script because of the "./", right?

"proc" is the name of the file. executing with "./". No relation with "cat".

Quote:
7-) Regarding the "cat proc" block, do you know how many lines can store or how is the capacity in memory before print them?
"cat proc" will show the contents of the file "proc" to the screen (STDOUT).


Hope it helps.
# 11  
Old 10-11-2011
Quote:
Originally Posted by anchal_khare
Most of the part you will understand yourself if you think about it.
I will try to help you explaining and/or the source where you can get the help. (man pages are the easiest and best way offcourse).

Hope it helps.
Many thanks anchal_khare, for sure it will help me a lot, I've read the links you suggested me and I understand many more things of your script now.

Great support and help from you.

Much appreciated.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change values in xml file?

I have xml file like below, i want change the values at default-value place of each argument name using shell script. like where argument name= protocol and default-value=tcp, where argument name =port and default-value= 7223, where argument name = username and default-value=test, example ... (12 Replies)
Discussion started by: s1s2s3s4
12 Replies

2. Shell Programming and Scripting

Change attribute value in xml using shell script

hi, i am new to unix and i have a problem. -------------------------------------------------------------- sebben.xml <envelope> <email> sebben@example.com </email> </envelope> script_mail written in the vi editor. #!/bin/sh script to change the value in attribute <email> echo... (3 Replies)
Discussion started by: sebbenw
3 Replies

3. Shell Programming and Scripting

To change Specific Lines in An XML file

hi Guys, this is my requirement, there is a huge xml file of this i have to change 3 lines with out opening the file /users/oracle > cat lnxdb-pts-454.xml|egrep "s_virtual|s_cluster|s_dlsnstatus" <cluster_port oa_var="s_clusterServicePort">9998</cluster_port> <host... (2 Replies)
Discussion started by: smarlaku
2 Replies

4. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

5. Shell Programming and Scripting

Change values in Log4j.xml using ksh script

Hi, I am new to UNIX and shell scripting. I have to create a shell script(ksh) which parses log4j.xml file for a given webservice name and change the corresponding value from INFO to DEBUG or vice-versa. My log4j.xml looks like:- <!-- Appender WEBSERVICENAME--> <appender... (3 Replies)
Discussion started by: sanjeevcseng
3 Replies

6. Shell Programming and Scripting

Shell script for a writing the directory structure to a file

Hi All, I am new user of shell scripting has come up with a problem. that I have a directory structure like : Home | |--------A | |----trunk | |-------A_0_1/ | | | |-------A_0_2/ | |--------B | ... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

7. 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

8. Programming

compare XML/flat file with UNIX file system structure

Before i start doing something, I wanted to know whether the approach to compare XML file with UNIX file system structure. I have a pre-configured file(contains a list of paths to executables) and i need to check against the UNIX directory structure. what are the various approches should i use ? I... (6 Replies)
Discussion started by: shafi2all
6 Replies

9. Shell Programming and Scripting

change function structure with perl (regExp)

Hello all i have some function what looks like this class.method("servantName").servantMethod(arg1,arg2,arg3) now i need to convert it to : class.method("servantName","servantMethod",arg1,arg2,arg3); is there any wasy way to do that consider that the arg1+2+3 can be also... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question