The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using grep and to remove all word with uppercase cfg UNIX for Dummies Questions & Answers 4 10-01-2008 06:56 AM
grep for a particular pattern and remove few lines above top and bottom of the patter fed.linuxgossip Shell Programming and Scripting 17 07-25-2008 09:29 AM
Script to remove log files kiranherekar Shell Programming and Scripting 1 03-02-2006 01:24 AM
remove files Nisha Shell Programming and Scripting 7 06-26-2002 01:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2008
basisvasis basisvasis is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
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 (permalink)  
Old 10-22-2008
sethcoop sethcoop is offline
Registered User
  
 

Join Date: Oct 2008
Location: United States
Posts: 34
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 (permalink)  
Old 10-22-2008
basisvasis basisvasis is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
I only want to remove the tags from these files, not the entire lines that contain these tags.
  #4 (permalink)  
Old 10-22-2008
sethcoop sethcoop is offline
Registered User
  
 

Join Date: Oct 2008
Location: United States
Posts: 34
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 (permalink)  
Old 10-22-2008
basisvasis basisvasis is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 9
sethcoop,

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

Thanks a lot.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0