0

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
4
  • 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
    Commented Aug 5, 2013 at 21:07
  • It's just a text file. Commented Aug 5, 2013 at 21:07
  • Each on its own line?
    – nerdwaller
    Commented Aug 5, 2013 at 21:08
  • Yes, each on it's own line. Commented Aug 5, 2013 at 21:09

1 Answer 1

1

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.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .