Sed/Awk line double

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

13throwaway

Posted 2013-08-05T21:02:09.210

Reputation: 3

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 – 2013-08-05T21:07:11.683

It's just a text file. – 13throwaway – 2013-08-05T21:07:56.643

Each on its own line? – nerdwaller – 2013-08-05T21:08:43.940

Yes, each on it's own line. – 13throwaway – 2013-08-05T21:09:35.603

Answers

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

nerdwaller

Posted 2013-08-05T21:02:09.210

Reputation: 13 366