Finding & Copying files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding & Copying files
# 1  
Old 10-20-2010
Finding & Copying files

Hello Smilie
can someone please help me with this task:
I am in the shell, in folder "Main"
below the folder Main are sub folders: "sourceA", "Source B", and "target"

in sourceA and source B are files, and in folder "Main" is a textfile, with filenames, one filename per line.

I need a shellscript that:
1. reads the textfile line per line...
2. finds the file either in sourceA or sourceB and copies it to "target"
3. or, if the searched file is in neither folder, writes an error like "File XY not found" into a new textfile

Thank you very much in advance for looking into this
# 2  
Old 10-20-2010
Looks very much like homework!
What have you done so far?
# 3  
Old 10-20-2010
maybe smthg like :

Code:
( find ./@(sourceA|sourceB) -type f -prune) | grep -f textfile | while read a
do
cp $a target/${a##*/}
done

This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 10-20-2010
homework?

Quote:
Originally Posted by vbe
Looks very much like homework!
What have you done so far?
Sorry, i was not participating in any classes or homework or the like here Smilie i really am mainly a ubuntu desktop user, i am not earning my money with unix or linux shell scripting, but need all in all three tips so far to get a one time problem i have there, done.

So, as i said, any help is appreciated Smilie
# 5  
Old 10-21-2010
thank you ctsngb, this worked perfectly well and helped me saving time a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

2. UNIX for Advanced & Expert Users

Challenges in finding and copying the block

Hi, I have a below challenging task where iam unable to find the block and copy the same into a file. I tried my luck,howver iam unable to reach the first and second step..Can anyone help me with a clue or with the commands so that i can give a try. 1. search the <number>9966993366</number>... (2 Replies)
Discussion started by: cskumar
2 Replies

3. Shell Programming and Scripting

Finding a text in files & replacing it with unique strings

Hallo Everyone. I have to admit I'm shell scripting illiterate . I need to find certain strings in several text files and replace each of the string by unique & corresponding text. I prepared a csv file with 3 columns: <filename>;<old_pattern>;<new_pattern> ... (5 Replies)
Discussion started by: gordom
5 Replies

4. UNIX for Dummies Questions & Answers

finding, copying, assembling

Hi everybody, I've been running some analyses, the results of which have been stored in a sequential manner with a directory structure like step0, step1, step2, ... for iterations 0-2, for example. Each iteration contains several nested folders, with three pieces of information I need. I need to... (1 Reply)
Discussion started by: JDenton
1 Replies

5. UNIX for Dummies Questions & Answers

Finding duplicates then copying, almost there, maybe?

Hi everyone. I'm trying to help my wife with a project, she has exported 200 images from many different folders, unfortunately there was a problem with the export and I need to find the master versions so that she doesn't have to go through and select them again. I need to: For each image in... (2 Replies)
Discussion started by: Rhinoskin
2 Replies

6. UNIX for Advanced & Expert Users

copying of files by userB, dir & files owned by userA

I am userB and have a dir /temp1 This dir is owned by me. How do I recursively copy files from another users's dir userA? I need to preserve the original user who created files, original group information, original create date, mod date etc. I tried cp -pr /home/userA/* . ... (2 Replies)
Discussion started by: Hangman2
2 Replies

7. Shell Programming and Scripting

Help in finding files & processing them

Hi All, I have a requirement to search 3 files in a directory and process them after they arrive. I know the names of the files and also the directory where I have to search them. These things are going to be constant. I used the "test -f" command to search a single file. That is working... (1 Reply)
Discussion started by: swatipevekar
1 Replies

8. UNIX for Dummies Questions & Answers

Finding and Copying Email

I have to create a bash script that will find Feedback emails and copy them to a labFeedback folder in my mail directory. I have an idea in my head on what commands can be used for this (find obviously among them). However, I have no idea where to start. I'm not sure what info needs to be given,... (1 Reply)
Discussion started by: Joesgrrrl
1 Replies

9. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

10. UNIX for Dummies Questions & Answers

finding and copying files !

Hi , I have a question relating to finding and copying files. i need to find the .pdf files from the specified directory which has subdirectories too. I only need .pdf files and not the directories and need to copy those files into my current directory. copy files from :... (5 Replies)
Discussion started by: bregoty
5 Replies
Login or Register to Ask a Question