How can I remove some xml tag lines using shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I remove some xml tag lines using shell script?
# 8  
Old 05-10-2013
I have no idea why it doesn't work for you!

I downloaded the XML file that you attached and ran the very same commands you tried, here is what I get:
Code:
$ grep -i "Prathyu" AMC_Exhibitions_Test_2005.xml | head
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>
                                <ReleaseIndicator>Prathyu</ReleaseIndicator>

Code:
$ grep -vi "Prathyu" AMC_Exhibitions_Test_2005.xml | head
<?xml version="1.0" encoding="UTF-8"?>
<PerformanceScheduleFeed xmlns="http://AMC.PerformanceSchedule.1.0">
        <Originator>amctheatres.com</Originator>
        <SystemName>Interface 262</SystemName>
        <FeedIdentifier>1927DBAB-9C04-4742-A3E0-3917E3556197</FeedIdentifier>
        <DateTimeCreated>2013-05-10T11:56:20</DateTimeCreated>
        <PerformanceScheduleFromDateTime>2011-11-18T00:00:00</PerformanceScheduleFromDateTime>
        <PerformanceScheduleToDateTime>2011-11-24T00:00:00</PerformanceScheduleToDateTime>
        <InternalReleaseList>
                <InternalRelease>

# 9  
Old 05-10-2013
Now I got it..why the code not working for me..Please see the attached file..this is how file looks in unix box..

The file which I sent before is the file which I formated in XML structure..

Yodha..can you please down load the new file and try the same code and let me know if it is working for you..
# 10  
Old 05-10-2013
Ok, I got it. Try sed then:
Code:
sed 's/<ReleaseIndicator>Prathyu<\/ReleaseIndicator>//g' AMC_Exhibitions_Test_2005.xml > AMC_Exhibitions_Test_2006.xml

# 11  
Old 05-10-2013
Thanks Yodha, it is working now..

Thanks Corona688 for helping me to resolve my solution..

Thank you Smilie

---------- Post updated at 04:02 PM ---------- Previous update was at 03:51 PM ----------

I am sorry for disturbing you guys again..I am trying to remove total line

Code:
<ReleaseIndicatorList><ReleaseIndicator>Prathyu</ReleaseIndicator></ReleaseIndicatorList>

from the same file by using Sed command which provided by yodha..

Code:
sed 's/<ReleaseIndicatorList><ReleaseIndicator>Prathyu<\/ReleaseIndicator><\/ReleaseIndicatorList>/// g' AMC_Exhibitions_Test_2005.xml > AMC_Exhibitions_Test_2006.xml

but I am getting error like

Code:
sed: -e expression #1, char 96: unknown option to `s'

I think I am missing something in writing code, can you please tell me which one is wrong here

Thanks in advance,
Prathyu

---------- Post updated at 04:08 PM ---------- Previous update was at 04:02 PM ----------

I got it again.. I just used the extra ' / ' symbol in my code..

I used the below code and it's working fine now..

Code:
sed 's/<ReleaseIndicatorList><ReleaseIndicator>Prathyu<\/ReleaseIndicator><\/ReleaseIndicatorList>// g' AMC_Exhibitions_Test_2005.xml > AMC_Exhibitions_Test_2006.xml

Thank you guys Smilie

Last edited by Scott; 05-10-2013 at 06:48 PM.. Reason: Code tags
# 12  
Old 05-10-2013
Quote:
Originally Posted by Prathyu
The file which I sent before is the file which I formated in XML structure..
So it really is one giant line then, not individual lines...

sed may work on your system but beware that many systems have 2048-byte line limits for tools like sed and awk.

Last edited by Corona688; 05-10-2013 at 06:19 PM..
# 13  
Old 05-10-2013
Is there is any other command which I can use for that kind of situations. Please let me know.
# 14  
Old 05-10-2013
Quote:
Originally Posted by Prathyu
Is there is any other command which I can use for that kind of situations. Please let me know.
If you have xmllint in your system, you can use it for formatting and pipe the results to sed:
Code:
xmllint --format AMC_Exhibitions_Test_2005.xml | sed ...

For further reference check the man page:
Code:
man xmllint

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Read xml tags and then remove the tag using shell script

<Start> <Header> This is header section </Header> <Body> <Body_start> This is body section <a> <b> <c> <st>111</st> </c> <d> <st>blank</st> </d> </b> </a> </Body_start> <Body_section> This is body section (3 Replies)
Discussion started by: RJG
3 Replies

3. Shell Programming and Scripting

How to remove html tag which has multiple lines in SHELL?

I want to clean a html file. I try to remove the script part in the html and remove the rest of tags and empty lines. The code I try to use is the following: sed '/<script/,/<\/script>/d' webpage.html | sed -e 's/<*>//g' | sed '/^\s*$/d' > output.txt However, in this method, I can not... (10 Replies)
Discussion started by: YuhuiFeng
10 Replies

4. Shell Programming and Scripting

Print a closing XML tag shell script

I have a shell script that does everything I need it to do. But, when I was testing it I realized it doesn't print the closing XML tag.... Does anyone know how to incorporate printing the XML tag with my script? I am using AWK any help would be appreciated. (4 Replies)
Discussion started by: risarose87
4 Replies

5. Shell Programming and Scripting

Modify XML tag using shell script

Hi All Need some help with a unix shell script. I have a XML file as shown below: <Root> <Service> <endPoint type="SOAP" protocol="http"> <provider>ABCD</provider> <urlRewrite>/service/xyz/getAccountDetails</urlRewrite> <timeout>30</timeout> </endPoint> </Service> <Service> <endPoint... (3 Replies)
Discussion started by: abhilwa
3 Replies

6. UNIX for Advanced & Expert Users

Shell Script to read XML tags and the data within that tag

Hi unix Gurus, I am really new to Unix Scripting. Please help me to create a shell script which reads the xml file and from that i need to fetch a particular information. For example <SOURCE BUSINESSNAME ="" DATABASETYPE ="Teradata" DBDNAME ="DWPROD3" DESCRIPTION ="" NAME... (2 Replies)
Discussion started by: SmilePlease
2 Replies

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

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

9. Shell Programming and Scripting

How to remove some xml tag lines using shell script

I have existing XML file as below, now based on input string in shell script on workordercode i need to create a seprate xml file for e.g if we pass the input string as 184851 then it find the tag data from <workOrder>..</workOrder> and write to a new file and similarly next time if i pass the... (3 Replies)
Discussion started by: balrajg
3 Replies

10. 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
Login or Register to Ask a Question