LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2004, 09:37 AM   #1
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Rep: Reputation: 15
easy way to wrap a lot of links for html output?


I have about 100 http://www... type strings that don't have the <a herf... tags around them (unformatted URLS for HTML output). Does any one know where I can get a script or something that would wrap all these unformatted URLs with the HTML <a herf... tags so I don't have to do them one at a time?

Thanks for any help,

The Rhino
 
Old 10-16-2004, 10:08 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Do you have all these strings in a text file or are they interspersed with other text or what?
 
Old 10-16-2004, 11:12 AM   #3
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Original Poster
Rep: Reputation: 15
A nice clean list of URLs
 
Old 10-16-2004, 12:03 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
I'm not good with shell scripts. But here's a quick C program you can use as a tool maybe:
Code:
itsme@itsme:~/C$ cat wrap.c
#include <stdio.h>
#include <string.h>

int main(void)
{
  char buf[4096];

  while(fgets(buf, sizeof(buf), stdin))
  {
    buf[strlen(buf)-1] = '\0';

    printf("<a href=\"%s\">%s</a>\n", buf, buf);
  }

  return 0;
}
itsme@itsme:~/C$ make wrap
cc     wrap.c   -o wrap
itsme@itsme:~/C$ cat temp.txt
http://www.google.com
http://www.yahoo.com
http://www.linuxquestions.org
itsme@itsme:~/C$ ./wrap < temp.txt
<a href="http://www.google.com">http://www.google.com</a>
<a href="http://www.yahoo.com">http://www.yahoo.com</a>
<a href="http://www.linuxquestions.org">http://www.linuxquestions.org</a>
itsme@itsme:~/C$

Last edited by itsme86; 10-16-2004 at 12:08 PM.
 
Old 10-16-2004, 02:53 PM   #5
the_rhino
Member
 
Registered: Sep 2004
Distribution: PCLinuxOS
Posts: 59

Original Poster
Rep: Reputation: 15
Thanks for the code. This may very well do what I want but I have no idea how to use it.
 
Old 10-17-2004, 01:24 PM   #6
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Look at his shell prompts "itsme@itsme:~/C$". He's showing you how to use the program...

-twantrd
 
Old 10-18-2004, 12:59 AM   #7
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
sed 's/\(.*\)/<a href="\1">\1<\/a>/' url_list.txt > some.html
 
Old 10-20-2004, 12:40 PM   #8
zchoyt
Member
 
Registered: Feb 2003
Location: Boise ID
Distribution: fedora
Posts: 156

Rep: Reputation: 30
The c example works fine for me.
 
  


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
html links from various sources rblampain Programming 2 11-24-2005 10:32 PM
HTML links in signatures? BajaNick LQ Suggestions & Feedback 3 12-20-2004 02:32 AM
copy HTML and paste links TxLonghorn Linux - Software 2 02-24-2004 10:56 PM
Duplicate Links In Bookmarks.html MarcRJacobs Linux - Newbie 0 06-11-2003 01:29 PM
Can't open html links in email Glock Shooter Linux - Newbie 1 06-04-2002 12:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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