LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2010, 01:51 AM   #1
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Rep: Reputation: 0
line numbers to html in mixed content


I have huge files, wherein some lines begin with a number. I want to convert that number to a bookmark link

Sample file:

Code:
C.S. Lewis (I think) wrote:
1 If war is ever
2 legal, then peace
3 is sometimes
4 sinful.
Text without numbers too
I need the numbers to be <a name tags where the id is the letter x and the number that is at the beginning of the line:

Code:
C.S. Lewis (I think) wrote:
<a name="x1">1</a> If war is ever
<a name="x2">2</a> legal, then peace
<a name="x3">3</a> is sometimes
<a name="x4">4</a> sinful.
Text without numbers too
I'm not sure why I can't get this, but after hours of 3 line long seds and endless while read lines, grepping ^[[:digits:]]s I can't figure it out. Any helpful suggestions would be appreciated... the files are lengthy, and there are bunches of them to go through.

Thanks
 
Old 08-21-2010, 03:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Hi,

Is this what you are looking for:

sed -i.bak 's/^\([0-9][0-9]*\)\( .*\)/<a name="x\1">\1<\/a>\2/' infile

Makes changes in place and saves original with a .bak extension.

Hope this helps.
 
1 members found this post helpful.
Old 08-21-2010, 12:24 PM   #3
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
...Hope this helps.
It does, thank you very much
 
Old 08-21-2010, 12:40 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
You're welcome
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] SSL Virtual Hosts, CSS and IE Mixed Content fukawi2 Linux - Server 7 09-18-2010 12:16 AM
[SOLVED] Trying to number every other line and append those numbers to end of line kmkocot Programming 7 04-23-2010 12:17 PM
Grep's line numbers parsed into one line of output. judgex Programming 8 08-14-2006 05:22 AM
sending html text message with zip file attachment; Content-Type: multipart/mixed phelpsj Programming 1 06-22-2006 09:50 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 08:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:16 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration