0

I have a script that outputs a column of text. I want to prepend each entry in the column with a string stored as a variable. How can I do this?

For example, consider the command

$ echo -e "john\npaul\ngeorge\nringo"
john
paul
george
ringo

Now, I'd like to prepend each entry in this column with the value of the environment variable $HOME. I've tried piping into awk like this:

$ echo -e "john\npaul\ngeorge\nringo" | awk '{printf("%s%s\n", $HOME, $1)}'
johnjohn
paulpaul
georgegeorge
ringoringo

This output is not what I'm looking for. What am I doing wrong?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

0 Answers0