Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell equivalent to PHP's preg_replace()

Greetz folks.

I'm looking for a way to do the same stuff than PHP's preg_replace() does (search text matching a regular expression and replace it) in a shell script.

So, consider the following file.

<a href="http://example.com/">Website #1</a>
<a href="http://example.net/">Website #2</a>
<a href="http://example.org/">Website #3</a>

And I want to get this:

http://example.com/
http://example.net/
http://example.org/

Is there a way to do this? Thanks.

like image 381
seriousdev Avatar asked Dec 20 '10 15:12

seriousdev


1 Answers

You can use sed as:

sed -r 's/.*href="([^"]*)".*/\1/' file

See it

like image 87
codaddict Avatar answered Oct 30 '22 04:10

codaddict