Change name of files to their paths -- find loop


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Change name of files to their paths -- find loop
# 1  
Old 02-27-2013
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
Code:
find . -name output.csv | xargs -I {} cp -iv {} ./results

I have tried the loop but dont face the same problem
Code:
find . -name output.csv | while read i
 do
	name=$(basename $i) 
	cat $i > ${name}.csv
 done

can someone help me plz?

Last edited by A-V; 02-27-2013 at 09:53 PM..
# 2  
Old 03-01-2013
I wonder if simply running:
Code:
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/^\.-//'")
This User Gave Thanks to Smiling Dragon For This Post:
# 3  
Old 03-01-2013
Thanx a lot, thats helpful to know ... managed to get it using dirname
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is it possible to change paths inside a bash script?

i have some script with some paths inside it. The idea is to some files which is on desktop copy and move to another location. Problem is that inside script is similar to this: cp test1.zip /root/help/ because I allways have another zip files, does it possible to have some input which ask me... (18 Replies)
Discussion started by: tomislav91
18 Replies

2. Shell Programming and Scripting

REGEX to separate paths by whitespace and do a loop

I am trying to do in a single line to take a list of paths separated by whitespace and then loop thru all the paths that were wrote but my regex is not working, I have echo {3} | sed 's/ //g' | while read EACHFILE do ..... But for some reason is only taking always the first path that I... (7 Replies)
Discussion started by: jorgejac
7 Replies

3. Programming

Can't find paths.h

I wasn't sure which forum to post this in. I am trying to compile logsurfer. After I run configure and the make, I get a complaint that paths.h is not found. I see three places where there is a paths.h: /usr/include/pgsql/server/optimizer/paths.h... (3 Replies)
Discussion started by: brownwrap
3 Replies

4. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

5. Shell Programming and Scripting

Find text containing paths and replace with a string in all the python files

I have 100+ python files in a single directory. I need to replace a specific path occurrence with a variable name. Following are the find and the replace strings: Findstring--"projects\\Debugger\\debugger_dp8051_01\\debugger_dp8051_01.cywrk" Replacestring--self.projpath I tried... (5 Replies)
Discussion started by: noorsam
5 Replies

6. Solaris

SAN - Hard loop / prefered paths - help

Hi all Right, Im a little bit thick when it comes to SAN :-) IVe got a dual port qlc in a solaris 10 server. Its all connected and I can see a number of disks. The SAN guy here has asked me about preferred paths, i.e. as the dual ports are connected to two fabrics, etc device will have 4... (2 Replies)
Discussion started by: sbk1972
2 Replies

7. Shell Programming and Scripting

find multiple paths

How do i find files in more than one directory? I searched through forums, but could not land into the right thread. I tried something like find dir1|dir2 -name file1 but it doesn't work. Please suggest. (5 Replies)
Discussion started by: krishmaths
5 Replies

8. Shell Programming and Scripting

To find and replace paths consisting \

Hi all, I am new to unix and wanted to replace the string consisting \ with nothing. I tried the following but did not help. for y in `ls DIV*`; do sed s/C:\\Project\\AML\\bin//g $y > temp mv temp $y done I actually want to remove any occurance of C:\Project\ABC\bin in... (4 Replies)
Discussion started by: cv_pan
4 Replies

9. Shell Programming and Scripting

help with a 'while read' loop to change the names of files

Hi, I am new to scripting, so any help on this would be much appreciated. I am trying to rename a bunch of files, taking the names sequentially from a list read in another file... # ls oldnames file_1 file_2 file_3 # cat names red yellow green I want the files to take on the... (6 Replies)
Discussion started by: starsky
6 Replies

10. Shell Programming and Scripting

find common elements in 2 files (for loop)

Hi, i'm new here (and to scripting too). I was hoping for some help in comparing two files. i have a file called 'file1' with a list of names in the following format: adam jones paul higgins kelly lowe i also have another file which may contain some of the names but with a lot of... (4 Replies)
Discussion started by: ibking
4 Replies
Login or Register to Ask a Question