Add sth to end of each line, but only for specific files

Hi.

I have a list with files, and I would like to add a variable to the end of each line of each file in this list. The files are in a folder together with a large number of other files which I don't want to change.

My code is:

for file in 'cat ../list'
do
    sed 's/$/\/R:_0/' $file >> $file.tmp
    mv $file.tmp $file
done

But of course it doesn't work. Can someone help please?

Cheers,

Kat

The main reason is probably the use of regular single quotes instead of backquotes, but it may also fail for other reasons (file names with spaces or command line length). If there is one file name per line in file.list, try:

while read file
do
  sed 's/$/\/R:_0/' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
done < ./list

Yes, it was the nasty back quotes! Thanks!

I have a different problem now. I would like to copy the last 5 lines in each file on that list to a textfile.

I wrote this code:

for i in `cat ../list`
do
    tail -n 5 chp_blizzard_*  $i >> out.data
done

I have around 700 lines in the list, each line contains the name of one file...but the ouput I get is a 3GB textfile with millions of lines because it doesn't only copy the lines from the files on that list but from other files as well.

while read i
do
  tail -n 5 "$i" >> out.data
done < ../list

Mh...the files for reading, the script and the list are all in the same folder. Nevertheless, when I execute the script I get the message "tail: cannot open file for reading, no such file or directory. The script looks like this:

while read i
do
  tail -n 5 "$i" >> ../out.data
done < ./list