2

I have a loop in the script below. It is not working as I want. I need to put the $LINE value in front of each column. While it puts "$LINE" instead of it is value:

cat list | while read LINE ; do
sed 's/^/$LINE\t/g' $LINE.alf > $LINE.joined
done
Ali
  • 81
  • 1
    use double quotes for variable substitution... "s/^/$LINE\t/" and g flag is not needed as start of line can be matched only once – Sundeep Jan 25 '17 at 05:29
  • I tried does not work – Ali Jan 25 '17 at 06:15
  • doesn't work is too broad.. what went wrong? is there a error message? also, it would help if you give a bigger picture of your problem... why are you using cat+while... – Sundeep Jan 25 '17 at 06:21

1 Answers1

2

It will not expand variables in side of a single quoted ' string. Try:

cat list | while read LINE ; do
sed 's/^/'"$LINE"'\t/' $LINE.alf > $LINE.joined
done