sed delete range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed delete range
# 1  
Old 05-08-2011
sed delete range

Hi

I would like to delete ranges of text from an html file;
In the sentence; aqua>Stroomprobleem in Hengelo verholpen <a href="107-01.html"><font color=yellow>107</a>

With several sentences like this in that file, where the text between <a href a> varies, so it needs to be deleted in the range from <a till a>.

I tried;
Code:
sed -n '\<a\,\a>\s \#.*\ \g' [file-name].html

replacing it with nothing but this doesn't do anything, what am I doing wrong?
(bit of a noob here, so probably something stupid Smilie

Last edited by Franklin52; 05-09-2011 at 05:58 AM.. Reason: code tags
# 2  
Old 05-08-2011
You mean you want to delete the link, defined between '<a href' and '</a>' tags, right? Use sed's 's' command (substitute)
Here:
Code:
$ echo 'aqua>Stroomprobleem in Hengelo verholpen <a href="107-01.html"><font color=yellow>107</a>' | sed 's!<a href.*</a>!!'
aqua>Stroomprobleem in Hengelo verholpen

The exclamation marks are delimiters, and any char will do, as long as there is exactly three of them there.
Beware, however, that pattern matching is greedy; so if you happen to have more links on one line, it will eat up everything between the first '<a href' and the last '</a>':
Code:
$ echo 'Beginning<a href="whatevah">link1</a>This is eaten too<a href="again">link2</a>end of line' | sed 's!<a href.*</a>!!'
Beginningend of line

# 3  
Old 05-09-2011
Thanks, worked like a charm.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies

2. UNIX for Beginners Questions & Answers

How to delete row in csv file on date range?

I want to delete row in csv file , which row value from 2009-10-01 to 2011-06-03 using script.my csv row data look like: 2009-10-01 2011-03-30 2011-03-31 2011-04-01 2011-06-03 2011-06-30 2011-07-01 2011-09-28 ... (7 Replies)
Discussion started by: rakibul639
7 Replies

3. Shell Programming and Scripting

Delete lines falling in a range

Hi All, I have a file which contains lakhs of records 0136812368126 03000 Statement 1237129372189 02321 JIT 0136812368126 05000 terminal 1237129372189 05001 Utilise Is there an option to delete all lines which fall within the range 05000 to 05999? I tried... (6 Replies)
Discussion started by: swasid
6 Replies

4. Shell Programming and Scripting

how to use sed to get 2nd range?

Hi all, Is there a way to use the sed command to get the second range? For instance: sample.dat: ------------- 11111 22222 33333 44444 ------------- using "sed -n '/^ping/,/^$/p' sample.dat can get the first 2 lines. But is there a way to get the first 4 lines, from... (4 Replies)
Discussion started by: sleepy_11
4 Replies

5. UNIX for Dummies Questions & Answers

Date range command (and delete)

Hello. Newbie here.... I basically have a directory with tens of thousands (literally) subdirectories and need to delete those that are older than 2008 (hundreds) with all their contents. I've looked through all the RM parameters and still can't quite figure out how to specify the data range... (7 Replies)
Discussion started by: pqmomba8
7 Replies

6. Shell Programming and Scripting

delete rows between closest pattern or range

Hi I am having some problom deleting the lines between two specific lines in a file. need to delete lines between two closest lines. i.e need to find the closest range or pattern in a file with repeating patterns. Sample Input: WARNING <some text in n number of lines> ERROR:2597... (10 Replies)
Discussion started by: sudheer1984
10 Replies

7. Shell Programming and Scripting

Grep a string in a range and delete the line

Hi, i need to delete a lines after searching a particular string but this searching should only happen after the 4th line.. basically imagine a file like this From: abcd.yahoo.com To: cdeb.yahoo.com Subject: hi all sdfsd sadasd asdasd dfsdf From: abcd.yahoo.com To:... (3 Replies)
Discussion started by: depakjan
3 Replies

8. Shell Programming and Scripting

sed pattern range

Hi guys, trying to replace a '#' with a ' ' (space) but only between the brackets '(' and ')' N="text1#text2#text3(var1#var2#var3)" N=`echo $N |sed '/(/,/) s/#. //'` echo $N Looking for an output of "text1#text2#text3(var1 var2 var3)" Any ideas? (15 Replies)
Discussion started by: mikepegg
15 Replies

9. Shell Programming and Scripting

Sed Range command

Hi, I am trying to get all the log entries in a log file based on start and end times, I have tried to use the following but couldnt get the desired output: sed -n '/start/,/end/ p' file & newtime=`echo "$time" | cut -d -start | cut -d" " -start` Kindly help me, Thanks (0 Replies)
Discussion started by: openspark
0 Replies

10. Shell Programming and Scripting

Sed Range Issue

OK, so for a grand overview of what I'm trying to do: I've got 2 files that are mostly like. The file format is: data data data data data data data data data data (2 Replies)
Discussion started by: Wrathe
2 Replies
Login or Register to Ask a Question