salah-1
salah-1

Reputation: 1399

Find and Replace string and what's following it

I have the following links in a sql dump file(.sql). I need to use 'sed or grep with regex' or something to replace each occurance of #cheese-pasta= and whatever is after it including slash.

Example:

 <a href="somelink/#cheese-pasta=2011-13\">
  <a href="somelink/#cheese-pasta=\">

After the replacement, this will look like:

<a href="somelink/">

I could jus do somethin like sed /#cheese-pasta=/ /g but, problem is that string is followed by other stuff and i want replace the stuff that's following it upto the quote that ends the link tag ()

Thanks a lot.

Upvotes: 0

Views: 92

Answers (1)

ruakh
ruakh

Reputation: 183456

You could write:

sed 's/#cheese-pasta=[^\\]*\\//g'

which will replace #cheese-pasta=, followed by zero or more characters that aren't backslashes, followed by a backslash.

Alternatively:

sed 's/#cheese-pasta=[^"]*"/"/g'

(same concept, but using " instead of \ to find the end of the text to replace).

Upvotes: 1

Related Questions