You are not logged in.

#1 2007-10-03 12:50:34

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Sed expression

Hi,

How would I remove anything between brackets using a sed command.  Eg:

<tr><td>foo</td> <td>bar</td></tr>

would turn into:

foo bar

I tried sed "s#\<.*\>##g" but that remove everything from the first "<" to the last ">".  How do I match the first ">"?

Thanks

Offline

#2 2007-10-03 13:00:39

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Sed expression

Would this do :

sed "s#<[^>]*>##g

pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#3 2007-10-03 13:09:30

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Re: Sed expression

Perfect, many thanks.

Offline

#4 2007-10-03 15:04:29

magnum_opus
Member
Registered: 2005-01-26
Posts: 132

Re: Sed expression

How about this:

stuff
/*Multi line
comment */
more stuff
/*more comments*/

to

stuff
more stuff

Offline

#5 2007-10-03 15:16:04

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: Sed expression

from: http://lists.samba.org/archive/linux/20 … 04283.html

It's not a 1-liner sed, but it seems to work.

strip-c-comments.sh

#!/usr/bin/sed -f

# if no /* get next 
/\/\*/!b

# here we've got an /*, append lines until get the corresponding
# */
:x
/\*\//!{
N
bx
}

# delete /*...*/
s/\/\*.*\*\///

You'd run it like:

$ cat test.html | ./strip-c-comments.sh

Offline

#6 2007-10-03 17:47:07

magnum_opus
Member
Registered: 2005-01-26
Posts: 132

Re: Sed expression

wow.
cool thanks.
but wow.

Offline

Board footer

Powered by FluxBB