?
Solved

Sort HTML File

Posted on 2014-01-05
1
Medium Priority
?
337 Views
Last Modified: 2014-01-05
I want to take an HTML file, and edit it so that it is easier to scrape the data in it. I wish to edit the file, so that two things happen.

1.) all <img ... tags are replaced with a carriage return and then <img ...

2.) all </img> tags are replaced with </img> and a carriage return.  

So, a file that has:

blah<img alt="" src="http://test.com/test.jpg"></img><img alt="" src="http://test.com/test2.jpg"></img>

becomes:

blah
<img alt="" src="http://test.com/test.jpg"></img>

<img alt="" src="http://test.com/test2.jpg"></img>
0
Comment
Question by:stakor
[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
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 39758393
perl -pe 's/(?=<img)/\n/g;s{(?<=</img>)}{\n}g' <<END
blah<img alt="" src="http://test.com/test.jpg"></img><img alt="" src="http://test.com/test2.jpg"></img>
END
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

800 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