Remove < or > from between 2 tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove < or > from between 2 tags
# 1  
Old 01-30-2014
Remove < or > from between 2 tags

Hi

I'm fairly new to all of this so hope you can help

Within a shell script I need to remove either of these characters

<
>

from between 2 tags in an xml file. The current code is removing the tags and therefore the loading of my xml file is failing

Any ideas?

Thanks

Craig
# 2  
Old 01-30-2014
Welcome to forum, if you show sample input and expected output we can help. while posting your data kindly use codetags.

Akshay
# 3  
Old 01-30-2014
Input
Code:
<refa>Part<Description</refa>

Desired Result
Code:
<refa>Part Description</refa>

Thanks
# 4  
Old 01-30-2014
Quote:
Originally Posted by Spac3Monket
Input
Code:
<refa>Part<Description</refa>

Desired Result
Code:
<refa>Part Description</refa>

Thanks
Code:
$ echo "<refa>Part<Description</refa>" | awk -F">" '{split($2,A,"<");$2=A[1]" "A[2]"<"A[3]}1' OFS=">"
<refa>Part Description</refa>

# 5  
Old 01-30-2014
Hello,

Following may too help.

Code:
echo "<refa>Part<Description</refa>" | sed 's/\(.*Part\)\(.*\)\(Description.*\)/\1 \3/g'


Output will be as follows.

Code:
<refa>Part Description</refa>


NOTE: But it will work for only this given text.



Thanks,
R. Singh
# 6  
Old 01-30-2014
Code:
sed 's#\(.\)\(<\)\([^/]\)#\1 \3#g' file

# 7  
Old 01-30-2014
OSX 10.7.5, default bash terminal...
Bizarre but there is always a way:-
Code:
#!/bin/bash --posix
text="<refa>Random string to find gt>or<lt.</refa>"
newtext=""
for subscript in $( seq 6 1 $[ ( ${#text} - 8 ) ] )
do
	if [ "${text:$subscript:1}" == "<" ] || [ "${text:$subscript:1}" == ">" ]
	then
		newtext="$newtext "
	else
		newtext="$newtext${text:$subscript:1}"
	fi
done
text="<refa>$newtext</refa>"
echo "$text"

Result...
Code:
Last login: Thu Jan 30 19:20:55 on ttys000
AMIGA:barrywalker~> chmod 755 gt_lt.sh
AMIGA:barrywalker~> ./gt_lt.sh
<refa>Random string to find gt or lt.</refa>
AMIGA:barrywalker~> _

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove multiline HTML tags from a file?

I am trying to remove a multiline HTML tag and its contents from a few HTML files following the same basic pattern. So far using regex and sed have been unsuccessful. The HTML has a basic structure like this (with the normal HTML stuff around it): <div id="div1"> <div class="div2"> <other... (4 Replies)
Discussion started by: threesixtyfive
4 Replies

2. Shell Programming and Scripting

How to remove the values inside the html tags?

Hi, I have a txt file which contain this: <a href="linux">Linux</a> <a href="unix">Unix</a> <a href="oracle">Oracle</a> <a href="perl">Perl</a> I'm trying to extract the text in between these anchor tag and ignoring everything else using grep. I managed to ignore the tags but unable to... (6 Replies)
Discussion started by: KCApple
6 Replies

3. Shell Programming and Scripting

Remove html tags with particular string inside the tags

Could someone, please provide a solution to the following: I would like to remove some tags from the "head" of multiple html documents across the web site. They look like <link rel="alternate" type="application/rss+xml" title="Business and Investment in the Philippines"... (2 Replies)
Discussion started by: georgi58
2 Replies

4. Shell Programming and Scripting

Need the script to remove common strings,tags etc

I have a file say "example.xml" and the contents of this example.xml are <project name="platform/packages/wallpapers/Basic" path="packages/wallpapers/Basic" revision="225e410f054c4ad5c828b0fec9be1b47c4376711"/> <project name="platform/packages/wallpapers/Galaxy4"... (3 Replies)
Discussion started by: acdc
3 Replies

5. Shell Programming and Scripting

remove spaces between tags

I am having the data.txt file as follows. ------- <RMService> <ResControl> <ResultCode>FATAL</ResultCode> <ServiceTime>38</ServiceTime> <DWLControl> <requesterLanguage>100</requesterLanguage> <requesterLocale>en</requesterLocale> <requesterName>NCO A Batch... (6 Replies)
Discussion started by: kmanivan82
6 Replies

6. Shell Programming and Scripting

remove html tags,consecutive duplicate lines

I need help with a script that will remove all HTML tags from an HTML document and remove any consecutive duplicate lines, and save it as a text document. The user should have the option of including the name of an html file as an argument for the script, but if none is provided, then the script... (7 Replies)
Discussion started by: clicstic
7 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 html tags with bash

Hello, is there a way to go through a file and remove certain html tags with bash? If it needs sed or awk, that'll do too. The reason why I want this is, because I have a monitor script which generates a logfile in HTML and every time it generates a logfile, the tags are reproduced. The tags... (4 Replies)
Discussion started by: dejavu88
4 Replies

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

10. Linux

How to remove only html tags inside a file?

Hi All, I have following example file i want to remove all html tags only, Input File: <html> <head> <title>Software Solutions Inc., </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor=white leftmargin="0" topmargin="0"... (2 Replies)
Discussion started by: btech_raju
2 Replies
Login or Register to Ask a Question