grep, remove and conconate -- xml files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep, remove and conconate -- xml files
# 1  
Old 10-22-2008
grep, remove and conconate -- xml files

suse linux 10 here.

I have two xml files here and both contain <sf> and </sf> tags in almost beginning and towards the end fo the files.
I need to remove the </sf> tag from the first file and the <sf> from the second file and combine both the files into one. I have tried the following script but i am getting a resulting output file which is empty. Please advise.

#!/bin/sh
# this is myscript.sh
if (test -e file1.xml) && (test -e file2.xml)
then
cat file1.xml|grep -v '</sf>'>billprint.xml
cat file2.xml|grep -v '<sf>'>>billprint.xml
fi


Just FYI: all my xml code is in one line

Last edited by basisvasis; 10-22-2008 at 08:40 PM..
# 2  
Old 10-22-2008
If all of the xml is on one line then the grep -v will remove your whole line from the output... since it is all on one line I would use sed to remove the </sf> and <sf> from the files...

Code:
$ cat t2.txt
<sf>thi si sa test</sf>
$ cat t2.txt | sed 's/<\/sf>//g'
<sf>thi si sa test
$ cat t2.txt | sed 's/<sf>//g'
thi si sa test</sf>
$

see how that works...
# 3  
Old 10-22-2008
I only want to remove the tags from these files, not the entire lines that contain these tags.
# 4  
Old 10-22-2008
Using "sed" will replace all appearances of "<sf>" and "</sf>" in your file. Then you can append them together.

Since your data is all on one line then "grep -v" will not work for what you want.
# 5  
Old 10-22-2008
sethcoop,

your suggestion worked like a charm. I never knew that -v option of grep would remove the entire line.

Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

2. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

3. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

4. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

5. UNIX for Dummies Questions & Answers

Urgent - XML Attribute Remove

Hi I have got a XML file which has got content as follows: <FUNCall81110000 Tag="81110000" CallDate="25/08/11" CallTime="00:03:22" TotalUsageValue="30" MeasurementUnit="1"/> I want to remove TotalUsageValue="30" only and TotalUsageValue="XXXXX" here XXX can be any value. (1 Reply)
Discussion started by: muchyog
1 Replies

6. Shell Programming and Scripting

Remove files with ps -ef |grep

ps -ef |grep qdaemon |grep /usr/bin/ksh TOC # d_prod 487630 5034194 0 Oct 27 - 0:00 /usr/bin/ksh /usr/lib/lpd/pio/etc/piojetd umhn-7w36-ps1 9100 -d s /var/spool/qdae mon/tCVAf7a d_prod 6709402 5034194 0 02:50:19 - 0:00 /usr/bin/ksh /usr/lib/lpd/pio/etc/piojetd... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

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

8. Shell Programming and Scripting

Remove lines from XML based on condition

Hi, I need to remove some lines from an XML file is the value within a tag is empty. Imagine this scenario, <acd><acdID>2</acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> I... (3 Replies)
Discussion started by: giles.cardew
3 Replies

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

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