How can i copy a list of files with different names into others directory have the same name?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How can i copy a list of files with different names into others directory have the same name?
# 15  
Old 08-08-2010
thank you it's working now
but how can i do the same but if i have the files:
Code:
10_10_asdadfsdfad.txt
10_10_11_asdawqefwkjasd.txt
10_10_11_12_asdafjjhoqwd.txt

i want to put them in exist directory thart i have on my system
directories:
Code:
10_10
10_10_11
10_10_11_12

i want to put file : "10_10_asdadfsdfad.txt" in directory "10_10"

i want to put file : "10_10_11_asdawqefwkjasd.txt" in directory "10_10_11"

i want to put file : "10_10_11_12_asdafjjhoqwd.txt" in directory "10_10_12"

how can i do that we can use the same code u have give it to me but how can we edit it to make that possible .
thank you for your help & time, I need ur reply as faster as possible

Last edited by Scott; 08-08-2010 at 07:46 AM.. Reason: Code tags please...
# 16  
Old 08-08-2010
Quote:
i want to put file : "10_10_11_12_asdafjjhoqwd.txt" in directory "10_10_12"
I presume that should be

Quote:
i want to put file : "10_10_11_12_asdafjjhoqwd.txt" in directory "10_10_11_12"
Code:
for FILE in 10_10*.txt; do
  cp "$FILE" ../test2/"${FILE%_*}"
done

(if any of your filenames have additional underscore (_) characters, this won't handle that)
# 17  
Old 08-08-2010
cp: cannot access 10_10*.txt
error msg
thanks for ur reply
# 18  
Old 08-08-2010
Quote:
Originally Posted by t17
cp: cannot access 10_10*.txt
error msg
thanks for ur reply
Then I guess either that your .txt files are in another directory, have another name, or you don't have permission to read them.
  • What directory are you running the script from?
  • What directory are the .txt files in?
  • Are all the .txt files in the same directory?
  • What directory do you want to copy them to?
  • Are the .txt files all to be copied to directories in the same base directory (i.e ../test2)?
# 19  
Old 08-08-2010
i fixed and check it and now it's runing thank you alott Smilie for your help
but i need another favor from you
what if i have another file called 5_54_6532467 i want to copy with them in another direcotry but have the same name of it 5_54_6532467

---------- Post updated at 07:58 AM ---------- Previous update was at 07:54 AM ----------

how can i copy all of them in one code ??
i want to put file : "10_10_asdadfsdfad." in directory "10_10"

i want to put file : "10_10_11_asdawqefwkjasd" in directory "10_10_11"

i want to put file : "10_10_11_12_asdafjjhoqwd" in directory "10_10_12"

i want to put file : "5_54_6532467" in directory "5_54_6532467"
# 20  
Old 08-08-2010
Should be something like this:
Code:
filecnt=0

for file in 10_10*
do
  directory=${file%_[a-zA-Z]*}
  mkdir -f ../test2/${directory}
  cp "$file" ../test2/${directory}/
  filecnt=$(( $filecnt + 1 ))
done

echo "$filecnt files copied"


Last edited by Franklin52; 08-08-2010 at 02:24 PM.. Reason: Exchange 2 lines after do keyword and correcting code
# 21  
Old 08-09-2010
thanks alott it workss Smilie Smilie Smilie
what if i want to but if condition to check out if the file exists in the directory or not
if the file exists then check the size of the file if the size zero then copy it if the file bigger that zero then don't copy. if the file not exists copy it. and i want to make the code to read the path as paramter of the file "pwd".
thanks for ur help
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. Shell Programming and Scripting

How to list files names and sizes in a directory and output result to the file?

Hi , I'm trying to list the files and output is written to a file. But when I execute the command , the output file is being listed. How to exclude it ? /tmp file1.txt file2.txt ls -ltr |grep -v '-' | awk print {$9, $5} > output.txt cat output.txt file1.txt file2.txt output.txt (8 Replies)
Discussion started by: etldeveloper
8 Replies

3. UNIX for Dummies Questions & Answers

List Directory names which have the file

Hi All, Can any one help me to list out the directory names which contain the specified file. See for example File name : file.201307014.LKT Have the directory structure as below. /app/work/data/INDIA/file.201307014.LKT /app/work/data/AMERICA/file.201307014.KTP... (5 Replies)
Discussion started by: Balasankar
5 Replies

4. Shell Programming and Scripting

How to copy selective list of files to a directory?

Hi I have 3 directories indexes_with_ts indexes_without_ts process_indexes in each directories it contains *.sql how do I accomplish this: for all the files found in indexes_without_ts, copy the corresponding file in indexes_with_ts to process_indexes. i.e. for... (2 Replies)
Discussion started by: jediwannabe
2 Replies

5. Shell Programming and Scripting

Copy list of files from a keyword list to another directory

Hello, I have a folder with a massive amount of files, and I want to copy out a specific subset of the files to a new directory. I would like to use a text file with the filenames listed, but can't get it to work. The thing I'm hung up on is that the folder names in the path can and do have... (5 Replies)
Discussion started by: twjolson
5 Replies

6. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

7. Shell Programming and Scripting

Copy files on a list to another directory

Hi. I have a list with file names like testfile1.wav testfile2.wav testfile3.wav and a folder that contains a large number of wav files (not only the ones on the list). I would like to copy the files whose names are on the list from the wav file directory to a new directory. I... (5 Replies)
Discussion started by: Bloomy
5 Replies

8. Shell Programming and Scripting

how to copy files followed by list of names of all the files in /etc?

....... (2 Replies)
Discussion started by: pcbuilder
2 Replies

9. Shell Programming and Scripting

how can i copy a list of files with different names into others directory have the same name

dear all. how can i copy a list of files with different names into others directory have the same name like i have 3 files 10_10 10_10_11 10_10_11_12 and i have 3 directories 10_10 10_10_11 10_10_11_12 how can i make a loop to cp this files into the directory have the same name like... (0 Replies)
Discussion started by: t17
0 Replies

10. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies
Login or Register to Ask a Question