removing empty tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing empty tags
# 1  
Old 08-06-2008
removing empty tags

Hi,

I have a file as shown below.
<crown:clinicalData>
<crown:alb date="2008-07-10" lowValue="3.50" method="BCG" value="3.50"/>
<crown:cre date="2008-07-10" value="9.5"></crown:cre>
<crown:ktvHdAd>
</crown:ktvHdAd>
<crown:ktvPdAd>
</crown:ktvPdAd>
</crown:clinicalData>


I want to remove the empty tags. i.e I want to remove

<crown:ktvHdAd>
</crown:ktvHdAd>

and

<crown:ktvPdAd>
</crown:ktvPdAd>

If it happens to have records in between the tags, then I do not want to delete.

Can any of you know good approaches to it?

Thanks
Vijay
# 2  
Old 08-06-2008
Code:
perl -i.bak -0777 -pe's|\n*<\S*?>\s*</\S*?>||g' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

2. Shell Programming and Scripting

awk :quick question removing empty line.

How to write in awk to remove lines starting with "#" and then process the file: This is not working: cat file|awk '{if ($0 ~ /^#/) $0="";print NF>0}' When I just give cat file|awk '{if ($0 ~ /^#/) $0="";print }' it prints the blank lines . I don't wnat the blank lines along with the... (15 Replies)
Discussion started by: rveri
15 Replies

3. UNIX for Dummies Questions & Answers

Removing empty lines at the end of a Tab-delimited file

I'm trying to remove all of the empty lines at the end of a Tab delimited file. They have no data just tabs. I've tried may things, here are a couple: sed /^\t.\t/d File1 > File2 sed /^\t{44}/d File1 > File2 What am I missing? (9 Replies)
Discussion started by: SirHenry1
9 Replies

4. UNIX for Dummies Questions & Answers

Removing empty folders

Hello, I have a folder that contains all my music. Recently, I started using a different media player, and I let it manage my music folder. It has sorted all my music neatly in folders by artist and album. However, all the old folders that the songs used to be in are still there, yet they are... (2 Replies)
Discussion started by: emveedee
2 Replies

5. Ubuntu

dpkg: warning: while removing directory not empty

Hi, I am getting this warning messages when I run dpkg --purge dpkg -r apt-get remove --purge aptitude purge with sudo permission to remove completely a custom application that is installed through debian dpkg command. Some of the directories in that package install path is still left out... (0 Replies)
Discussion started by: royalibrahim
0 Replies

6. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

7. UNIX for Dummies Questions & Answers

Removing empty folders using 'find'

Hey there! I try to use 'find' to remove empty directories like this: find . -depth -type d -empty -exec rm -rf {} ';' It works just fine, but there are some directories i want to exclude. So i tried to do sth like this: find . -depth -type d -empty -exec grep -v "not this one please" -exec... (5 Replies)
Discussion started by: deTTo
5 Replies

8. UNIX for Dummies Questions & Answers

Removing empty folders using the "find" command

Hi I'm trying to remove empty sub-folders from 1 main folder using the find method, but the "- empty" parameter isn't recognized by my Unix version. Any idea how to implement such thing? Thanks. (3 Replies)
Discussion started by: biot
3 Replies

9. UNIX for Dummies Questions & Answers

How to empty a file without removing it.

I used to be able to do the following command on HP while largefile was being written to. > echo " " > largefile When I try the same on Solaris I get a message that the file already exists. Is there a parameter that I need to setup in my env ? Thanks in advance (8 Replies)
Discussion started by: jxh461
8 Replies

10. Programming

Removing empty spaces and adding commas

I have a file which contains numbers as follows: 1234 9876 6789 5677 3452 9087 4562 1367 2678 7891 I need to remove the empty spaces and add commas between the numbers like: 1234,9876,6789,5677,3452, 9087,4562,1367,2678,7891 Can anyone tell me the command to do... (4 Replies)
Discussion started by: jazz
4 Replies
Login or Register to Ask a Question