Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a list like this.

  • Bob
  • Jim
  • Steve

Is there a way in bash to turn that into a list like this?

  • <a href="http://example.com/Bob"> Bob
  • <a href="http://example.com/Jim"> Jim
  • <a href="http://example.com/Steve"> Steve
share|improve this question
    
Where is the list coming from? That is probably the best way to start and give you some ideas. If it is a bash array, then use of awk or sed is probably unnecessary. If it's just an array (i.e. list=("Bob", "Jim", "Steve")) then you could do for i in "${list[@]}"; do echo <a href="http://example.com/${i}">${i}</a>; done. –  nerdwaller Aug 5 '13 at 21:07
    
It's just a text file. –  13throwaway Aug 5 '13 at 21:07
    
Each on its own line? –  nerdwaller Aug 5 '13 at 21:08
    
Yes, each on it's own line. –  13throwaway Aug 5 '13 at 21:09

1 Answer 1

up vote 1 down vote accepted

This should work fine:

#/usr/bin/env bash

while read n; do
    echo "<a href=\"http://example.com/${n}\">${n}</a>"
done < ${1}

If you made that a script, then you would call it with ./scriptname.sh filename.txt and it just prints it to the console. (Note: I extrapolated your question to include a </a> as well.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.