Change name of files to their paths -- find loop

Dear All,
I have many sub-folders but each of them have a file with same name but different data.
I want to either move or copy them into a new folder but they need to have the path of where they are coming as part of their name...
I have managed to find the files but dont know how to change the name

find . -name output.csv | xargs -I {} cp -iv {} ./results

I have tried the loop but dont face the same problem

find . -name output.csv | while read i
 do
	name=$(basename $i) 
	cat $i > ${name}.csv
 done 

can someone help me plz?

I wonder if simply running:

find . -name "output.csv" | while read filename
do
  cp "$filename" `echo "$filename" | sed 's#/#-#g'`
done

Might do the trick...
It'll put ".-" in front of each one due to the . path to find, but you can cut that out with sed if you need to (add "| sed 's/^\.-//'")

1 Like

Thanx a lot, thats helpful to know ... managed to get it using dirname