Sponsored Content
Top Forums Shell Programming and Scripting remove XML parent start and end tags in same file Post 302465373 by durden_tyler on Friday 22nd of October 2010 09:25:57 AM
Old 10-22-2010
Code:
$
$ # list all XML files in this directory
$ ls -1 *.xml
f1.xml
f2.xml
f3.xml
$
$ # show the content of all 3 XML files
$ cat f1.xml
<DummyLevel>
<level1> </level1>
<level2> </level2>
<level3> </level3>
<level4> </level4>
<level5> </level5>
<level6> </level7>
</DummyLevel>
$
$ cat f2.xml
<DummyLevel>
<level1> </level1>
<level2> </level2>
<level3> </level3>
<level4> </level4>
<level5> </level5>
<level6> </level7>
</DummyLevel>
$
$ cat f3.xml
<DummyLevel>
<level1> </level1>
<level2> </level2>
<level3> </level3>
<level4> </level4>
<level5> </level5>
<level6> </level7>
</DummyLevel>
$
$ # Run a Perl one-liner to perform inline edit in each XML file.
$ # Each file is backed up first.
$ perl -i.bak -pe 's/(<DummyLevel>|<\/DummyLevel>)\n//' *.xml
$
$ # show the content of each XML file after the operation
$ cat f1.xml
<level1> </level1>
<level2> </level2>
<level3> </level3>
<level4> </level4>
<level5> </level5>
<level6> </level7>
$
$ cat f2.xml
<level1> </level1>
<level2> </level2>
<level3> </level3>
<level4> </level4>
<level5> </level5>
<level6> </level7>
$
$ cat f3.xml
<level1> </level1>
<level2> </level2>
<level3> </level3>
<level4> </level4>
<level5> </level5>
<level6> </level7>
$
$

HTH,
tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove unwanted XML Tags

I have set of sources and the respective resolution. Please advice how to resolve the same using Unix shell scripting. Source 1: ======= <ext:ContactInfo xmlns:ext="urn:AOL.FLOWS.Extensions"> <ext:InternetEmailAddress>AOL@AOL.COM</ext:InternetEmailAddress> </ext:ContactInfo> Resoultion... (1 Reply)
Discussion started by: ambals123
1 Replies

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

3. UNIX for Dummies Questions & Answers

Extract a specific number from an XML file based on the start and end tags

Hello People, I have the following contents in an XML file ........... ........... .......... ........... <Details = "Sample Details"> <Name>Bob</Name> <Age>34</Age> <Address>CA</Address> <ContactNumber>1234</ContactNumber> </Details> ........... ............. .............. (4 Replies)
Discussion started by: sushant172
4 Replies

4. Shell Programming and Scripting

remove some XML tags

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... (1 Reply)
Discussion started by: id_2pc
1 Replies

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

6. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

7. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

8. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

9. Shell Programming and Scripting

Split a file by start and end row.

I have a file which looks something as following, I would like to split to several files, The start and end of each file is 'FILE' and end with 'ASCII... ' . At the same time for each file in the first column add 100 and also second column add 100 the rest of the column as it is , see example of... (2 Replies)
Discussion started by: tk2000
2 Replies

10. Shell Programming and Scripting

Search a String between start and end of a block in a file

Hi, I have a scenario where I want to display the output based on the pattern search between the start and end of a block in a file, we can have multiple start and end blocks in a file. Example give below, we need to search between the start block abc and end block def in a file, after that... (5 Replies)
Discussion started by: G.K.K
5 Replies
All times are GMT -4. The time now is 02:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy