unix - Delete Special Word Using sed -
i use sed remove occurances of line if , if this
<ab></ab>
if line, not want delete it
<ab>keyword</ab>
my attempt that's not working:
sed '/<ab></ab>/d'
thanks insight. i'm not sure what's wrong should not have escape anything?
i'm using shell script named temp execute this. command this:
cat foobar.html | ./temp
this temp shell script:
#!/bin/sh sed -e '/td/!d' | sed '/<ab></ab>/d'
it looks have couple of problems here. first /
in close-tag. sed
uses delimit different parts of command. fortunately, have escape \
. try:
sed '/<ab><\/ab>/d'
here's example on machine:
$ cat test <ab></ab> <ab></ab> <ab>test</ab> $ sed '/<ab><\/ab>/d' test <ab>test</ab> $
the other problem i'm not sure purpose of sed -e '/td/!d'
is. in it's default operating mode, don't need tell not delete something; tell want delete.
so, on file called input.html
:
sed '/<ab><\/ab>/d' input.html
or, edit file in-place, can do:
sed -i -e '/<ab><\/ab>/d' input.html
additionally, sed
lets use character want delimiter; don't have use /
. if you'd prefer not escape input, can do:
sed '\@<ab></ab>@d' input.html
edit
in comments, mentioned wanting delete lines contain </ab>
, nothing else. that, need what's called anchoring match. ^
character represents beginning of line anchoring, , $
represents end of line.
sed '/^<\/ab>$/d' input.html
this match line contains (literally) </ab>
, nothing else @ all, , delete line. if want match lines contain whitespace too, no text other </ab>
:
sed '/^[[:blank:]]*<\/ab>[[:blank:]]*$/d' input.html
[[:blank:]]*
matches "0 or more whitespace characters" , called "posix bracket expression".
Comments
Post a Comment