Solved

Linux single field extract from HTML

Posted on 2013-12-27
2
288 Views
Last Modified: 2013-12-28
Hi,

Can someone help out please with a linux command (been trying sed) to extract the src string from the HTML below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
... a whole bunch of html including other img tags...
</script>
<img src="/path/to/file/12345667.jpg" alt="" /></body>
</html>

I would like to pipe this HTML file into the command and have the command output just the src of the very last IMG tag in the file (/path/to/file/12345667.jpg in this case), which I will assign to a bash variable for subsequent use.

Very grateful
BT
0
Comment
Question by:brothertom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 39742721
Try this
sed -ne '/src/'p filename  | sed 's/.*src=[^\/]*\([^ "]*\).*/\1/'

Open in new window

0
 

Author Closing Comment

by:brothertom
ID: 39743239
Thanks farzanj.

Tiny refinement for the actual file did the trick...

sed -ne '/img src/'p filename  | sed 's/.*src=[^\/]*\([^ "]*\).*/\1/' | tail -1

BT
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question