Removing text between two static strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing text between two static strings
# 1  
Old 02-15-2010
Removing text between two static strings

Hi everyone,
I need to replace the text between two strings (html tags) and I'm having trouble figuring out how to do so. I can display the text with sed but I'm not having any luck deleting the text between the two strings.

My file looks like this:
Code:
<oths>test</oths><div class="text">1928 oakland (1)</div></td>
<oths>tes2t</oths><div class="text">1932 oakland (01)</div></td>

I need the output to look like this:
Code:
<oths>test</oths><div class="text"></div></td>
<oths>test2</oths><div class="text"></div></td>

So how do I find and remove any text between <div class="text"> and </div>? Thanks in advance for assistance with my issue!

Last edited by Scott; 02-17-2010 at 01:32 PM.. Reason: Added code tags
# 2  
Old 02-15-2010
Code:
 sed -e 's/\(<div\sclass\=\"text\">\)[^<]*\(<\/div>\)/\1\2/g' abc.txt

HTH,
PL
# 3  
Old 02-17-2010
Thanks daptal. Your example was very helpful and got me going in the right direction. Here's what worked for me:
Code:
sed -e 's/\(\<div class="text"\>\)[^<]*\(<\/div>\)/\1\2/g' file.txt

Thanks again for your help.

Last edited by Scott; 02-17-2010 at 01:35 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add static text in perl

I am trying to add a static value to a field in perl. Basically, what happens is a file is created and "null" results in the fields then after some manipulation a field (AB) is split and the text from that is parsed into the desired fields. All that works great what doesn't is the line in bold... (20 Replies)
Discussion started by: cmccabe
20 Replies

2. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

3. Shell Programming and Scripting

Removing string between two particular strings in a line

Hi, I have a file with following format: 1|What is you name (full name)?|Character 2|How far is your school ?|Numeric Now I need to remove everything inside brackets () or . There can be more than one pair of brackets. The output file should look like: 1|What is you name?|Character... (8 Replies)
Discussion started by: ppatra
8 Replies

4. Shell Programming and Scripting

script in perl for removing strings between a file

I have file that looks like: ATOM 2517 O VAL 160 8.337 12.679 -2.487 ATOM 2518 OXT VAL 160 7.646 12.461 -0.386 TER ATOM 2519 N VAL 161 -14.431 5.789 -25.371 ATOM 2520 H1 VAL 161 -15.336 5.698 -25.811 ATOM 2521 H2 VAL 161 -13.416 10.529 17.708 ATOM 2522 H3 VAL 161 -14.363 ... (4 Replies)
Discussion started by: kanikasharma
4 Replies

5. SuSE

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

6. Programming

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

7. Shell Programming and Scripting

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

8. Shell Programming and Scripting

Perl removing strings from a variable value

Dear all, I have a variable called $abc, which the value is something like below, *** *********** : ***** where * can be anything. I need to remove all but the final characters until last whitespace. example grd groupstudy : tutor6/7 becomes tutor6/7 something like if... (2 Replies)
Discussion started by: tententen
2 Replies

9. AIX

removing static route

#netstat -nr (shows the following with more static routes) 192.168.18.202 10.129.155.1 UGH 0 29 en0 - - and i just want to remove the above one i tried #smitty rmroute destination type= net dest add = 192.168.18.202 default gateway= 10.129.155.1 net... (1 Reply)
Discussion started by: pchangba1
1 Replies
Login or Register to Ask a Question