SED/AWK/PERL(GNU userland) - how to substitute pattern A but not pattern B?

1

First, I am using GNU userland so you can assume I use Bash, GNU coreutils...

I have a HTML and I want to change all

href="foobarz"

into

href=""

However, I don't want to change any line containing the word css (not case-sensitive)

'href="fooCsSbarz"'

should remain unchanged

I am currently using the command

$ cat foo.html | sed -e 's/href="[^"]*"/href=""/g' > bar.html

but it cannot retain those lines containing the word css (not case-sensitive)

Actually, any tool available in *nix is welcomed, like sed, awk, perl...

Thank for your help!

Alex Vong

Posted 2015-04-08T02:32:15.410

Reputation: 113

Answers

1

From here.

You can use:

sed '/[Cc][Ss][Ss]/! s/href="[^"]*"/href=""/g' foo.html > bar.html

user1794469

Posted 2015-04-08T02:32:15.410

Reputation: 256

Thanks a lot! That thread 's title is not 'grep-friendly'... – Alex Vong – 2015-04-08T04:12:59.823