LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 12: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, 02:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 11:24 AM   #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, 11:40 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
  


Reply



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-17-2010 11:16 PM
[SOLVED] Trying to number every other line and append those numbers to end of line kmkocot Programming 7 04-23-2010 11:17 AM
Grep's line numbers parsed into one line of output. judgex Programming 8 08-14-2006 04:22 AM
sending html text message with zip file attachment; Content-Type: multipart/mixed phelpsj Programming 1 06-22-2006 08:50 AM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM

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

All times are GMT -5. The time now is 04:31 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
Open Source Consulting | Domain Registration