File Separation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Separation
# 8  
Old 04-02-2015
File separation using pattern XML tags

Hello Every one,

This is the actual code i am working on, Please shed some light on this issue, it will be great help


Name: Source_file.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE POWERMART SYSTEM "powrmart.dtd">
<POWERMART CREATION_DATE="04/01/20151">
<REPOSITORY NAME="INFA""Oracle">
<FOLDER NAME="zvronges" GROUP=""r"
<TABLEATTRIBUTE NAME ="Sql Query" VALUE =""/>
</FOLDER>
<FOLDER NAME="AAAETL_UTILITY_SH" GROUP="" OWNER="Administrator"
PRECISION ="30" SCALE ="0"/>
</FOLDER>
<FOLDER NAME="zvsandineni" GROUP="" OWNER="Administrator">
<SOURCE BUSINESSNAME =">
</FOLDER>
</REPOSITORY>
</POWERMART>

These are the outputs i am expecting, This should give different files based on the folder name, if the
folder name starts with "Z" , this is going to separate file, if not we shall ignore the folders

First 4 lines will be common on all separate files ( Head -4 source_file.xml)
<Code for each developer name starting with "z">
Last 2 lines will be common on all files (tail -2 source_file.xml)



File_1
----------

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE POWERMART SYSTEM "powrmart.dtd">
<POWERMART CREATION_DATE="04/01/20151">
<REPOSITORY NAME="INFA""Oracle">
<FOLDER NAME="zvronges" GROUP=""r"
<TABLEATTRIBUTE NAME ="Sql Query" VALUE =""/>
</FOLDER>
</REPOSITORY>
</POWERMART>

File_2
----------

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE POWERMART SYSTEM "powrmart.dtd">
<POWERMART CREATION_DATE="04/01/20151">
<REPOSITORY NAME="INFA""Oracle">
<FOLDER NAME="zvsandineni" GROUP="" OWNER="Administrator">
<SOURCE BUSINESSNAME =">
</FOLDER>
</REPOSITORY>
</POWERMART>

Moderator's Comments:
Mod Comment DUPLICATE MERGED & APPENDED TO ORIGINAL

Last edited by jim mcnamara; 04-02-2015 at 10:35 PM..
# 9  
Old 04-02-2015
Please do not duplicate threads. Thanks.
# 10  
Old 04-03-2015
Sure thanks
# 11  
Old 04-03-2015
There's no folder name starting with "Z". For your upper case FOLDER, try
Code:
awk     'BEGIN          {CLHD=1}
         /^<FOLDER/     {CLHD=0; CLTR=0; FN++}
         CLHD           {HD=HD?HD ORS $0:$0; next}
         CLTR           {TR=TR?TR ORS $0:$0; next}
                        {P[FN]=P[FN]?P[FN] ORS $0:$0}
         /^<\/FOLDER>/  {CLTR=1}
         END            {for (p in P) print HD ORS P[p] ORS TR > "FILE" p}
        ' file

# 12  
Old 04-03-2015
Hi Rudic, sorry i meant the folder starting with lower case 'z' folders

This ones in the below code.
Only these folders are eligible for file separation, the onces with out 'z' in the front need to be ignored.

"zvronges" and "zvsandineni"
# 13  
Old 04-04-2015
Try
Code:
awk     'BEGIN          {CLHD=1}
         /^<FOL.*ME="z/ {CLHD=0; CLTR=0; CLDT=1;FN++}
         CLHD           {HD=HD?HD ORS $0:$0; next}   
         CLTR           {TR=TR?TR ORS $0:$0; next}   
         CLDT           {P[FN]=P[FN]?P[FN] ORS $0:$0}
         /^<\/FOLDER>/  {CLTR=1; CLDT=0}
         END            {for (p in P) print HD ORS P[p] ORS TR > "FILE" p}
        ' file

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum up formatted numbers with comma separation

I need to sum up the values in field nr 5 in a data file that contains some file listing. The 5th field denotes the size of each file and following are some sample values. 1,775,947,633 4,738 7,300 16,610 15,279 0 0 I tried the following code in a shell script. awk '{sum+=$5} END{print... (4 Replies)
Discussion started by: krishmaths
4 Replies

2. Shell Programming and Scripting

Read xml file till script finds separation and run again for next input and so on

Hi All, I have one query, I managed to run script with user inputs through command line or with 1 file. But I need to read a txt file/xml file in which user can mention multiple sets of answers and script should run for each set till it reach the EOF. Thanks in advance for example, the file... (3 Replies)
Discussion started by: rv_champ
3 Replies

3. Shell Programming and Scripting

How to determine column separation format?

Hi there, say I have a line with multiple columns but with different separation formats: spaces, tabs.. Is it possible to have AWK print the separation format between each column? (10 Replies)
Discussion started by: la2015
10 Replies

4. Shell Programming and Scripting

metacharacters separation

I have prepared a script to submit a string in a txt file. However there are somethings that I have to check before submitting the string in the txt file. One of those checks is to determine whether the string entered contains any metacharacters. I have tried sth like; echo "string" | grep -v ... (3 Replies)
Discussion started by: ozum
3 Replies

5. Shell Programming and Scripting

nawk -- separation of records on basis of number of fields

A file file1.txt exists having records like The delimiter being "|" X|_|Y|_|Z|_| (number of fields 7) A|_|B|_| (number of fields 5) X|_|Z|_|H|_| (number of fields 7) A|_|D|_|S|_| (number of... (4 Replies)
Discussion started by: centurion_13
4 Replies

6. Shell Programming and Scripting

Help need to write a script on column separation for syslog output in perl

HI Pros, I have a issue.I need to write a script to parse the logs got from syslog server and update the same in my database.I need the following output.I donot know perl and I heard it very easy to write in perl I have the sample log I need each column seperated by commas and all equals... (0 Replies)
Discussion started by: iron_michael86
0 Replies

7. Shell Programming and Scripting

Unwanted field separation in awk

Hi everyone, My problem is strange, I cannot think of why this is happening. I have a set of data that looks like this: Although it does not look it, the fields are tab delimited. I have made sure of this, and awk does recognize them as such. However, it divides what I would expect... (2 Replies)
Discussion started by: ccox85
2 Replies

8. Shell Programming and Scripting

Joining three lines with comma separation

I have a file that looks like this: G. KRESSLAR 9618 W. APPALOOSA DRIVE SUN CITY, AZ 85373 SHIRLEY ALLEN 7272 W. VIA MONTOYA DRIVE GLENDALE, AZ 85310 LOUIS VALDEZ 244441 N. 86TH AVENUE PEORIA, AZ 85383 DONNA NEWBON 3231 W. DENTON #D PHOENIX, AZ 85017 SARAH WILSON 6534 W. PALO... (3 Replies)
Discussion started by: BCarlson
3 Replies
Login or Register to Ask a Question