1

If I have a line of text which looks like...

[garbage] <img src="[some url]" [garbage] /> [garbage]

Using sed, how can I get the URL that the image is pointing to? There are no other instances of src= on that line.

Clark Gaebel
  • 16,590
  • 19
  • 64
  • 92

2 Answers2

7
cat html | sed -n 's/.*<img src="\([^"]*\)".*/\1/p'

The -n /p idiom allows you to ignore all the other lines in the file (i.e. do a sed and a grep in one go), while "([^"]*)" just says find the stuff in the quotes.

Conrad Irwin
  • 1,292
  • 8
  • 11
0

Ruby (1.9+)

$ ruby -ne 'puts $_.scan(/img src=\"(.[^"]*)/)' file
kurumi
  • 24,217
  • 4
  • 43
  • 49