How to deal with replaced files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to deal with replaced files?
# 1  
Old 03-21-2013
How to deal with replaced files?

My task is to copy all files from many directories in one. The big problem i encounter is that some files in different directory have the same names. Is they are way to copy the files that have same names in a sub directory ( need to preserve the name of the files unchanged )

I have list with all the files i have to copy.
Example

Code:
/media/gogo/6651-FEAB/Desktop/Desktop.jpg
/media/gogo/6651-FEAB/Desktop/fatgen103-1.pdf
/media/gogo/6651-FEAB/Desktop.jpg
/media/gogo/6651-FEAB/DOCS/docs slamka/ExpertizaShablon.doc
/media/gogo/6651-FEAB/KARA/docs slamka/Pismo/Desktop.jpg
/media/gogo/6651-FEAB/DOCS/docs slamka/Pismo_Uvedomitelno-Shablon.doc
/media/gogo/6651-FEAB/DOCS/docs slamka/PrPedavane-Shablon.doc
/media/gogo/6651-FEAB/DOCS/original/PrPedavane/Strgoa/Desktop.jpg

I need to copy all the files in:
Code:
gogo@okk/home/gogo/Documents/Record

ps: the threat name is wrong if someone na change it to "How to deal with files who have the same name"

Last edited by gogok_bg; 03-21-2013 at 04:29 AM..
# 2  
Old 03-21-2013
Its not possible to have two files with the same name in one directory. One suggestion is, you can append a number to it.
For e.g., you could copy "Desktop.jpg" from different locations as "Desktop01.jpg", "Desktop02.jpg"... and so on...
# 3  
Old 03-21-2013
How can your destination directory hold "two files" with the same name?

Option (1) You have prefix/append extra characters for each duplicate file before copying
(2) Even in Destination directory maintain the directory structure.
# 4  
Old 03-21-2013
Sounds like a mess.

For example. it seems you have at least four copies of DeskTop.jpg so you would need at least three subdirectories to preserve all the files. What are you going to name those subdirectories so you can tell which files are where?

As other poster suggested, you could also append something to prevent duplicate file names. But sounds confusing.

Why do you want to copy all the files together into one directory in the first place? What's the advantage?

If there is a good reason to do this, I'm sure it could be done: Get name of file to copy. Test if file already in destination directory. If no, copy it. If yes, create new subdirectory and copy file to subdirectory instead.
# 5  
Old 03-21-2013
Is they are way to make script that copy the files that have same names in a sub directory Smilie ?

---------- Post updated at 02:35 AM ---------- Previous update was at 02:28 AM ----------

Quote:
Originally Posted by hanson44
Sounds like a mess.

For example. it seems you have at least four copies of DeskTop.jpg so you would need at least three subdirectories to preserve all the files. What are you going to name those subdirectories so you can tell which files are where?

As other poster suggested, you could also append something to prevent duplicate file names. But sounds confusing.

Why do you want to copy all the files together into one directory in the first place? What's the advantage?

If there is a good reason to do this, I'm sure it could be done: Get name of file to copy. Test if file already in destination directory. If no, copy it. If yes, create new subdirectory and copy file to subdirectory instead.
The advantage is easy access.

What you suggest looks exactly what i am after, but need assist with it: Get name of file to copy. Test if file already in destination directory. If no, copy it. If yes, create new subdirectory and copy file to subdirectory instead

I don't mind copy all the files from the list in a new destination preserving the folder tree as well, but again i need help because don`t know how to preserve the directory tree.

Last edited by gogok_bg; 03-21-2013 at 04:40 AM..
# 6  
Old 03-21-2013
It would help if you could compose a test case. Give a sample of eight or so file names with complete paths, and the final complete paths you want.

Of course it's possible to do most anything. But sometimes the cure is worse than the disease. Why do you want all the files in one directory? The whole point of having directories is to organize information. What would be the result if you took all the papers out of your file cabinet and emptied them onto your desk? Smilie Is there any chance you could use tar or zip to accomplish whatever you are trying to do?
# 7  
Old 03-21-2013
Quote:
Originally Posted by hanson44
It would help if you could compose a test case. Give a sample of eight or so file names with complete paths, and the final complete paths you want.

Of course it's possible to do most anything. But sometimes the cure is worse than the disease. Why do you want all the files in one directory? The whole point of having directories is to organize information. What would be the result if you took all the papers out of your file cabinet and emptied them onto your desk? Smilie Is there any chance you could use tar or zip to accomplish whatever you are trying to do?
Well actually the files i need to copy are files i was specifically looking for, and they have something in common, so getting them in the same directory wood not presan an issue.

Here is an example:

Code:
/media/gogo/6651-FEAB/Desktop/Desktop.jpg
/media/gogo/6651-FEAB/Desktop/fatgen103-1.pdf
/media/gogo/6651-FEAB/Desktop.jpg
/media/gogo/6651-FEAB/DOCS/docs slamka/ExpertizaShablon.doc
/media/gogo/6651-FEAB/DOCS/docs slamka/Pismo-Shablon.doc
/media/gogo/6651-FEAB/eks/blaaaak/backup/path/map.jpg
/media/gogo/6651-FEAB/DOCS/docs slamka/Pismo_Uvedomitelno-Shablon.doc
/media/gogo/6651-FEAB/DOCS/docs slamka/PrPedavane-Shablon.doc
/media/gogo/6651-FEAB/DOCS/docs slamka/експертиза.doc
/media/gogo/6651-FEAB/DOCS/doc/letter.doc
/media/gogo/6651-FEAB/linux/Best Practices v3_1.pdf
/media/gogo/6651-FEAB/linux
/media/gogo/6651-FEAB/linux/logo1.jpg
/media/gogo/6651-FEAB/linux/logo2.jpg
/media/gogo/6651-FEAB/priemo_predav protokol2.doc
/media/gogo/6651-FEAB/tragva/Snapshot-15.jpg
/media/gogo/6651-FEAB/files/leto/21661-Clipart-Picture-Illustration-Of-A-Collection-Of-10-Floral-Vines-And-Flourishes-In-Black-And-White.jpg

/media/gogo/6651-FEAB/експертизи/Other/Help/images/help_logo_top.png
/media/gogo/6651-FEAB/експертизи/eks/REGISTRI/Desktop.jpg
/media/gogo/6651-FEAB/eks/blaaak/Blanka Obekt 5 - HP.doc
/media/gogo/6651-FEAB/eks/blaaaak/Blanka Obekt DELL.doc
/media/gogo/6651-FEAB/eks/blaaaak/map.jpg

all this lines are in a file datafinal. Path to this file is:
Code:
/home/gogo/Desktop/datafinal

The files i will copy will be always from removable device, hard drive or flash, dunno if this is relevant.

Need the files here:
Code:
/home/gogo/Documents/filetumb

Do it anyway you can, all files in one directory with the files who have duplicated names put in a sub directory OR copy all files with they are path in the folder i pointed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to deal files with space in names?

I have a bash file as following: #!/bin/sh deal_file(){ printf $1 printf "\t is a file" echo } main(){ for file in `find "$1" ` do deal_file $file done } main $1 then I run ./t.sh .,get the following results: (1 Reply)
Discussion started by: 915086731
1 Replies

2. UNIX for Dummies Questions & Answers

How to deal with incomplete image files

Sorry for the odd title, but I couldn't think of an easy way to describe my issue. Background I have a home security system that continually sends (via FTP) 4 different still images to a directory on my personal website - cam0.jpg, cam1.jpg, etc. I've written an extremely basic html script to... (4 Replies)
Discussion started by: CinciJeff
4 Replies

3. Shell Programming and Scripting

variable value is not getting replaced

Hi, I am trying to generate list of employees from emp table who joined yesterday. emp.sh YEST=$(date --date='1 day ago' +%Y-%m-%d) cat emp.sql | mysql -u <user> -p<pass> -h <host> -P <port> -D <dbname> > emp.csv emp.sql select * from employee where join_date = '$YEST'; I expected... (3 Replies)
Discussion started by: ravi.videla
3 Replies

4. Shell Programming and Scripting

Performing a calculation on string to be replaced

Hi, I have a file with occurances of the string "TO_DATE(<number here>,'J')" at random places. I need minus 2400000 from the number and replace the string with "convert(date, dateadd(dd, <new number here>,'16 Nov 1858')". I'm finding this difficult as the string isn't necessarily in the... (9 Replies)
Discussion started by: user_invalid
9 Replies

5. Shell Programming and Scripting

awk next time replaced by none

Hi Everyone, 1.txt a b c d e f d g gg output: abc de (3 Replies)
Discussion started by: jimmy_y
3 Replies

6. Shell Programming and Scripting

comma replaced with pipe

Source data: "123","aaa bbb CCC","12000" "134","HHH,bbc","13000" i have a delimited file. i want to replace with the pipe.The sed command is not working for replacing a delimeter. Command : sed s/\,/\|/g filename Output : When i run the command it is replacing the columns value... (7 Replies)
Discussion started by: number10
7 Replies

7. Shell Programming and Scripting

How to deal with .tar.gz files in Linux?x

Dear all, there are more than 10 files with .tar.gz extension in my folder i didnt want to extract them i just want to run the query to fetch my necessary data from all the files. but when i run the command it untar the files in that folder. gunzip -c abc.tar.gz | tar -xf - | grep REC |... (0 Replies)
Discussion started by: jojo123
0 Replies

8. Programming

Can Mutex be replaced with anything?

Hi All, To avoid race condition, instead of using mutex, semaphore, spinlock etc.... Is there any other mechanism by which we can avoid race condition in an multi-threading environment. -Thanks (6 Replies)
Discussion started by: rvan
6 Replies

9. AIX

hdisk0 becomes hdisk2 after replaced

hello, I must've screwed something here.. I just had hdisk0 replaced by IBM.. now it shows up as hdisk2 instead. Before doing that, I've had it split from hdisk1, and reduced from rootvg. Just did a rmdev -dl hdisk2.. ran cfgmgr, but still shows up as hdisk2 instead of hdisk0.. help! (2 Replies)
Discussion started by: kiem
2 Replies

10. UNIX for Advanced & Expert Users

what commands are used to deal with core files on linux redhat???

how do you cause a running pocess to dump a core file on linux systems?? i tried sleep 100 & kill -SEGV PID but nothing is created also, what commands can be used to analyze them? (extract useful info from them) (2 Replies)
Discussion started by: TRUEST
2 Replies
Login or Register to Ask a Question