Sponsored Content
Full Discussion: Sed command to clean xml tag
Top Forums Shell Programming and Scripting Sed command to clean xml tag Post 302272451 by iamwha1am on Tuesday 30th of December 2008 04:02:45 PM
Old 12-30-2008
Sed command to clean xml tag

Hi,
Can someone help me come up with a generic sed command to clean a tag off its attributes?

For eg.
Input String - <tag attrib=new>This String</tag>
should undergo a sed transformation to get
Output String - <tag >This String</tag>

This works -
echo "<tag attrib=new>This</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/g'

<tag >This</tag>

However, the moment i add a space in there - it goes for a toss
echo "<tag attrib=new>This String</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/g'

<tag >This >

Resolved the above issue using a single replace -
echo "<tag attrib=new>This String</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/'

<tag >This String</tag>

However, it does not handle the scenario -
echo " <tag attrib=new>This String</tag>" | sed -e 's/\([^<\/A-Za-z]\)[^>]*>/\1>/'

>This String</tag>


Any inputs on this will be of great help.

Last edited by iamwha1am; 12-30-2008 at 05:28 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell command to remove some XML tag is needed

Hi all, I have a file which i have to remove some line from it, the lines that i have to remove from my file is as below: </new_name></w"s" langue="Fr-fr" version="1.0" encoding="UTF-8" ?> <New_name> and it is finding at the middle of my file, is there any command line in linux to do it or do... (10 Replies)
Discussion started by: id_2pc
10 Replies

2. Shell Programming and Scripting

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

3. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

4. Shell Programming and Scripting

awk command to insert a tag in XML

Hi All, I need a help on inserting a XML tag. Actual input <var> <nam>abcd</nam> <a1>.</a1> </var> if tag <a1>.</a1> is getting missed in XML like below <var> <nam>abcd</nam> </var> i need to insert wherever it is missed after <nam> tag and before </var> tag. Could anyone... (3 Replies)
Discussion started by: mohanalakshmi
3 Replies

5. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <gp> <mms>1110012</mms> <tg>988</tg> <mm>LongTime</mm> <lv> <lkid>StartEle=ONE, Desti = Motion</lkid> <kk>12</kk> </lv> <lv> <lkid>StartEle=ONE, Source = Velocity</lkid> <kk>2</kk> </lv> <lv> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

6. Shell Programming and Scripting

sed substition within XML tag

Hi all, I basically want to remove certain characters from within a certain XML tag: From: <mytagone>hello 1-2-3 world</mytagone> <mytagtwo>hello 1-2-3 world</mytagtwo> To: <mytagone>hello 1 2 3 world</mytagone> <mytagtwo>hello 1-2-3 world</mytagtwo> Is this possible using sed... (6 Replies)
Discussion started by: Jedimark
6 Replies

7. Shell Programming and Scripting

XML Parse between to tag with upper tag

Hi Guys Here is my Input : <?xml version="1.0" encoding="UTF-8"?> <xn:MeContext id="01736"> <xn:VsDataContainer id="01736"> <xn:attributes> <xn:vsDataType>vsDataMeContext</xn:vsDataType> ... (12 Replies)
Discussion started by: pareshkp
12 Replies

8. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

9. Shell Programming and Scripting

sed search and replace after xml tag

Hi All, I'm new to sed. In following XML file <interface type='direct'> <mac address='52:54:00:86:ce:f6'/> <source dev='eno1' mode='bridge'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ... (8 Replies)
Discussion started by: varunrapelly
8 Replies

10. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies
Agent::Tag::String(3pm) 				User Contributed Perl Documentation				   Agent::Tag::String(3pm)

NAME
Log::Agent::Tag::String - a constant tag string SYNOPSIS
require Log::Agent::Tag::String; # Inherits from Log::Agent::Tag. my $tag = Log::Agent::Tag::String->make( -name => "session id", -value => $session, -postfix => 1, -separator => " -- ", ); DESCRIPTION
This class represents a constant tag string. CREATION ROUTINE PARAMETERS
The following parameters are defined, in alphabetical order: "-name" => name The name of this tag. Currently unused. "-postfix" => flag Whether tag should be placed after or before the log message. By default, it is prepended to the log message, i.e. this parameter is false. "-separator" => string The separation string between the tag and the log message. A single space by default. "-value" => string The tag's value. AUTHOR
Raphael Manfredi <Raphael_Manfredi@pobox.com> SEE ALSO
Log::Agent::Tag(3), Log::Agent::Message(3). perl v5.10.0 2002-03-09 Agent::Tag::String(3pm)
All times are GMT -4. The time now is 10:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy