Solved

Sort HTML File

Posted on 2014-01-05
1
325 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
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help formulating a regex 6 47
pattern problem 9 65
Writing a parser for java language 4 61
File Find regex problem 4 58
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now