Delete blocks with no data..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete blocks with no data..
# 1  
Old 01-28-2006
Delete blocks with no data..

Hi,

I tried this but could not get it...
here is what I need I have an xml where I get all the data in blocks but some times I get empty blocks with no data...shown below..I need to delete only those blocks with no data, I tried couple of ways but could not do it..any help is appreciated...

<CeValueCSVExt2>
<CeValueValueID>COI_RATE</CeValueValueID>
<CeValueDuration>1</CeValueDuration>
<CeValueCharValue>ART </CeValueCharValue>
<CeValueAllowUpdateInd tc="1">True</CeValueAllowUpdateInd>
</CeValueCSVExt2>

<CeValueCSVExt3>
<CeValueAllowUpdateInd tc="1">True</CeValueAllowUpdateInd>
</CeValueCSVExt3>

<CeValueCSVExt17>
</CeValueCSVExt17>
The last block need to be deteted is there any command I can do it as part of script to delete those blocks like "<CeValueCSVExt17></CeValueCSVExt17>"

Thanks,
Girinath.
# 2  
Old 01-28-2006
Try perl....
Code:
#!/usr/bin/perl

open( FH, "girin.xml" ) || die "Couldn't open file...\n";

while ( <FH> ) {
   $data .= $_;
}

$data =~ s!<CeValueCSVExt[0-9]+>\n</CeValueCSVExt[0-9]+>\n!!g;

print $data;

close( FH );

Then...
Code:
/path/to/girin.pl > girin.new.xml && mv girin.new.xml girin.xml

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete data blocks based on missing combinations

Hello masters, I am filtering data based on completeness. A (Name , Group) combination in File2 is only complete when it has data for all subgroups specified in File1. All incomplete (Name , Group) combinations do not appear in the output. So for example , Name1 Group 1 in File2 is... (6 Replies)
Discussion started by: senhia83
6 Replies

2. Shell Programming and Scripting

Row blocks to column blocks

Hello, Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row: S02 Length Per S02 7043 3.864 S02 54477 29.89 S02 104841 57.52 S03 Length Per S03 1150 0.835 S03 1321 0.96 S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies

3. Shell Programming and Scripting

Difficult transposing of data from profiles blocks

Hello to all, I really hope some expert or awk guru could help me with this. I don't have how to begin and hope is not so difficult for somebody. I'll expecting how someone could resolve this problem I have to parse this. I have blocks of parameters for each MSISDN and I would like to extract... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

4. Shell Programming and Scripting

Extracting data blocks from file

Hi all, I want to extract blocks of data from a file depending on the contents of that block. The input file(table) has several blocks each starting with 'gene' in the first column. I want to extract only those blocks which do not have the expression '_T02' in the second column. Input file ... (3 Replies)
Discussion started by: newbie83
3 Replies

5. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

6. UNIX for Dummies Questions & Answers

Using SED to delete between two blocks.....and then repeating.

Hi All I'm still on my slow and painful self teach learning experience with SED. My latest issue is getting my head around how best to do the following. I have a file that's created using iwlist that I want to chop up into paragraphs then only keep the ones I see as potential threats. I... (3 Replies)
Discussion started by: Bashingaway
3 Replies

7. UNIX for Dummies Questions & Answers

Convert 512-blocks to 4k blocks

I'm Unix. I'm looking at "df" on Unix now and below is an example. It's lists the filesystems out in 512-blocks, I need this in 4k blocks. Is there a way to do this in Unix or do I manually convert and how? So for container 1 there is 7,340,032 in size in 512-blocks. What would the 4k block be... (2 Replies)
Discussion started by: rockycj
2 Replies

8. Shell Programming and Scripting

Delete Blank Lines Between DHCP Host Blocks

Hi All, I have a dhcpd.conf file that gets static hosts added and removed via a shell script. After sometime, there becomes huge gaps of space ( blank lines ) between each host block. I tried a couple of sed one-liners; but, I can't seem to get the output I'm looking for. Also, I would like... (4 Replies)
Discussion started by: cstovall
4 Replies

9. Shell Programming and Scripting

Delete blocks of lines from text file

Hello, Hello Firends, I have file like below. I want to remove selected blocks say abc,pqr,lst. how can i remove those blocks from file. zone abc { blah blah blah } zone xyz { blah blah blah } zone pqr { blah blah blah } (4 Replies)
Discussion started by: nrbhole
4 Replies

10. Shell Programming and Scripting

Sorting blocks of data

Hello all, Below is what I am trying to accomplish: I have a file that looks like this /* ----------------- xxxx.y_abcd_00000050 ----------------- */ jdghjghkla sadgsdags asdgsdgasd asdgsagasdg /* ----------------- xxxx.y_abcd_00000055 ----------------- */ sdgsdg sdgxcvzxcbv... (8 Replies)
Discussion started by: alfredo123
8 Replies
Login or Register to Ask a Question