LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 03-05-2008, 05:52 AM   #1
anupamsr
Member
 
Registered: Sep 2004
Location: Dreams
Distribution: Gentoo (since 2004.3) (and Windows XP)
Posts: 362

Rep: Reputation: 30
Help with regexp


Hi!

I have a html file with following data in it.

<h3>Some title</h3><a name="something"></a>
March 13
...
<h3>Some other title</h3><a name="something"></a>
Feb 21
...

I want to replace such instances with

<h3>Some title</h3><a name="March 13"></a>
...
<h3>Some other title</h3><a name="Feb 21"></a>
...

Is it possible? Perl/Pything/Shell anything is good. Shell is preferred.
 
Old 03-05-2008, 06:03 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 459

Rep: Reputation: 58
A pseudo code:
(1) If line begins with <h3>, then store it.
(2) If previous line was <h3>, then store the date, and rewrite the <h3> line with changed url, and also write the current line.
(3) else write the line.

btw. whats the use?

End
 
Old 03-05-2008, 06:11 AM   #3
anupamsr
Member
 
Registered: Sep 2004
Location: Dreams
Distribution: Gentoo (since 2004.3) (and Windows XP)
Posts: 362

Original Poster
Rep: Reputation: 30
To create a table of blog entries and uniquely name-reference them
The date is actually full "date -Ru" so for all practical purposes, it will be unique...
 
Old 03-05-2008, 06:19 AM   #4
anupamsr
Member
 
Registered: Sep 2004
Location: Dreams
Distribution: Gentoo (since 2004.3) (and Windows XP)
Posts: 362

Original Poster
Rep: Reputation: 30
Could you please tell me how to do it in perl? I don't remember it at all!
 
Old 03-05-2008, 06:43 AM   #5
anupamsr
Member
 
Registered: Sep 2004
Location: Dreams
Distribution: Gentoo (since 2004.3) (and Windows XP)
Posts: 362

Original Poster
Rep: Reputation: 30
This does the trick for the first time.
Code:
cat blog.html|sed ':a;N;$!ba;s/<\/h3>\n[ \t]*/<\/h3>/g'|perl -p -e "s,<h3>.*</h3>,<a name=\"$'\"></a>$&\n,g"
For a script that I can run on the generated file, I will have to dig into your algorithm
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regexp help cliff76 Linux - Newbie 3 03-07-2008 02:15 PM
regexp ovince Programming 8 06-17-2007 10:54 AM
ls and regexp ygloo Programming 8 10-05-2006 03:50 PM
little help for regexp EmOuBi Linux - Newbie 6 08-06-2005 02:19 AM
regexp help ... pld Programming 1 03-15-2005 03:45 PM


All times are GMT -5. The time now is 01:28 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration