Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using grep to get src attribute from html file

Tags:

regex

grep

How to chain grep to match images between double quotation marks?

$ cat final.html | grep -Po 'src=\".*?\"'
src="Remix-OS-Download-Option.png"
src="VMSetup1.png"
src="VMSetup2.png"
src="VMSetup3_001.png"
src="VMSetup4.png"
src="VMSetup5.png"
src="VMSetup6.png"

Expected result:

Remix-OS-Download-Option.png
VMSetup1.png
...
VMSetup6.png
like image 204
pouya Avatar asked Feb 28 '26 09:02

pouya


1 Answers

Hope this will be helpful. As we are using perl regular expression here you can check demo here

Pipe your Command with: grep -Po '="\K[^"]+'

Regex: ="\K[^"]+

1. ="\K this will match =" and \K will reset the current match.

2. [^"]+ match all except "

Complete command:

cat final.html | grep -Po 'src=\".*?\"' | grep -Po '="\K[^"]+'

Optionally you can try this one: cat final.html | grep -Po 'src="\K[^"]+'

like image 158
Sahil Gulati Avatar answered Mar 04 '26 07:03

Sahil Gulati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!