Register
It is currently Thu Dec 18, 2014 12:12 am

Using two lines of text create a Link with an embedded URL


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Thu Aug 16, 2007 9:19 am   

Joined: Wed Jul 04, 2007 5:11 pm
Posts: 8
Location: new york
Hi guys, I just wanted to say that I have been learning a lot of shell scripting thanks to this board .


On Weekends, I sometimes print the code from some of your scripts and I sit at the table trying to analyze each line so that I can learn from
your programs :)


I usually don't like ask questions because I want to really find the solution myself either through research
or by trial an error.

but this time, I have a problem that I can't figure out.

here is what I want to try to accomplish

I have this piece of text ,


Yahoo.com
http://www.yahoo.com
google.com
http://www.google.com
infoseek.com
http://www.info


One line contains a name and the next one a URL that points to their website.

I would like to cat the contents of the file to standard output and then pipe it to a program have it transformed like this

<a href="http://www.yahoo.com">Yahoo.com</a>
<a href="http://www.google.com">google.com</a>
<a href="http://www.infoseek.com">infoseek.com</a>

I have tried many things but I can't figure it out.


If you could give me some pointers or ideas that will be appreciated. :) Thanks so much.


Top
 Profile  
 PostPosted: Thu Aug 16, 2007 10:26 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
just curious... how did you get the original file? was it generated... or did you copy and paste from somewhere...
if generated, have it generate onto one line.. ex:
Code:
Yahoo.com|http://www.yahoo.com
google.com|http://www.google.com
infoseek.com|http://www.info.com

then you could cut the file up like
Code:
until ! read curLine
do
    desc=`echo "$curLine" | cut -d| -f1`
    url=`echo "$curLine" | cut -d| -f2`
    echo "<a href=\"${url}\">${desc}</a>" >> output.txt
done < original_file.txt


ofcourse if you aren't generating the original file... there would be other ways of doing it... i'll get into those another time.. if need be


Top
 Profile  
 PostPosted: Thu Aug 16, 2007 1:28 pm   

Joined: Wed Jul 04, 2007 5:11 pm
Posts: 8
Location: new york
jbsnake thank you for your help :)

I am going to try that right now. Basically I have an AIM robot

the robot name is RSSFeedBuddy. It is online if you want to check it out.

If you send the command cnn
it will give you the latests rss fee on CNN

just like this.

Provided by CNN RSS feed

American convicted in terror trial
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Stocks tumble on credit worries
http://rss.cnn.com/%7Er/rss/cnn_topstor ... /index.htm

Jenna Bush gets engaged
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Report: Vick deal includes prison
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Human remains found at bridge collapse
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Bodies line Peru streets after 8.0 quake
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Erin causes floods, Dean strengthens
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Noise detected in mine, drilling plan changed
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Iraqi women use prostitution to feed kids
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html

Federal ID plan raises privacy concerns
http://rss.cnn.com/%7Er/rss/cnn_topstor ... index.html


I don't want the URL to show i actually want the article name on top to contain a link so the only thing you see is a hyperlink like this

Human remains found at bridge collapse


The data that I am trying to convert is not actually a file it is actually a stream of text that results from extracting the RSS feed using
and XML parser. That result is sent to the screen and not to a file.

I am going to try to use your code to see if I can accomplish that. :)


Top
 Profile  
 PostPosted: Thu Aug 16, 2007 3:14 pm   

Joined: Wed Jul 04, 2007 5:11 pm
Posts: 8
Location: new york
Just wanted to let you know that the code you sent me worked really good.

usign the code you sent me i created a script called url.sh
that has this code on it.


until ! read curLine
do
desc=`echo "$curLine" | cut -d"|" -f1`
url=`echo "$curLine" | cut -d"|" -f2`
echo "<a href=\"${url}\">${desc}</a>" # >> output.txt
done


so basically I have my output piped to | ./url.sh and here is the new output.

Once i type cnn on my AIM robot i get.

RSSFeedBuddy:

Provided by CNN RSS feed

Turbulent Dow plummets before last-gasp recovery
American guilty of backing Islamic terror
Jenna Bush to wed a former Rove aide
Human remains found at bridge collapse
Bodies line streets after massive quake
Erin spawns tornadoes as Dean gets stronger
Mystery noise changes mine rescue
Iraqi women sell their bodies to buy food for kids
Poll: Half don't trust upcoming Iraq report
Hezbollah video game goes to war with Israel


All the titles are hyperlinked to their story :)

Thanks so much jbsnake.


Top
 Profile  
 PostPosted: Sat Aug 18, 2007 10:52 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
My pleasure. Just glad I could help. Good job on taking what I had and making it work for yourself. :wink: Without that, my code would have been useless.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP