Copy files with different extensions and same name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy files with different extensions and same name
# 8  
Old 09-16-2015
Yes , thanks it created the list!

But now i don't know how to create a loop to copy the wav files from the list to the image directory

Code:
filename="match"
while read -r line
do

done

i'm missing the command to find the same wav file in the dir from the "match" list (created by
Code:
grep -f

) and then copy to images on to have mirrored png/wav files

Last edited by Board27; 09-16-2015 at 12:22 PM..
# 9  
Old 09-16-2015
Assuming generated your list with grep -vf listA.lst listB.lst or something similar, you can then:-
Code:
grep -vf listA.lst listB.lst | while read file_ref
do
   cp -p wavsdir/$file_ref.wav target_dir
done

The -p flag on the cp will preserve the ownership and timestamp of the file, if that is important to you. You would need to run this as root to be able to do that, unless the id running the script already owns the files.

The | while read file_ref sets up the loop and sets the value of file_ref to each string returned from the grep in tuen, so you can work down the list.


Does that help?

I might have the logic the wrong way round, so you might need to sort out the order of the list files, the grep with or without the -v flag and the source directory and extension for the file being copied. To test it first, put an echo before the cp command, so it looks like this:-
Code:
do
   echo cp -p wavsdir/$file_ref.wav target_dir
done

If I've got it horribly wrong, please post the error messages so I can have another think.


Kind regards,
Robin

Last edited by rbatte1; 09-16-2015 at 12:21 PM.. Reason: Stronger warning about checking the logic.
This User Gave Thanks to rbatte1 For This Post:
# 10  
Old 09-16-2015
It just did the trick!

Thank you for the very educative lesson for a noob like me!

Regards
# 11  
Old 09-16-2015
Excellent. I'm glad it helped. You might need to be careful if you have a loop within a loop, but if you get stuck, let us know and we can try to help again.
Quote:
for a noob like me
We all had to start somewhere. You should see some of my early stuff! Smilie It's truly horrible, but as it works, there is no point replacing it. Until you know the tricks and options to do things, then you might feel a little lost. Smilie

Feel free to ask for more help. It works best if you can explain the overall objective, then have a go & show us how far you have got with code, files and input/output & errors so we can help you grow your skills and then be able to write and support your own code. Smilie


Cheers,
Robin
# 12  
Old 09-16-2015
sure i will ,

thanks again

Kind Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mv all files with different extensions to a new name

Hello all! I want to move several files foo.aux foo.log foo.pdf foo.tex to bar_foo.aux bar_foo.pdf bar_foo.tex I am on tcsh % mv foo.* bar_!#:1 is not working. Thank you for your help marek (11 Replies)
Discussion started by: marek
11 Replies

2. Shell Programming and Scripting

Find duplicate files but with different extensions

Hi ! I wonder if anyone can help on this : I have a directory: /xyz that has the following files: chsLog.107.20130603.gz chsLog.115.20130603 chsLog.111.20130603.gz chsLog.107.20130603 chsLog.115.20130603.gz As you ca see there are two files that are the same but only with a minor... (10 Replies)
Discussion started by: fretagi
10 Replies

3. Shell Programming and Scripting

looping through files with different extensions

Hi all, I am trying to make a for loop invoking files with different extensions (*.ugrd and *.vgrd) and I cant just make it work. Cant figure out how to load the files so as to use them in subsequent commands like the ones in this pseudo code. the files are arranged such that in one date for... (8 Replies)
Discussion started by: ida1215
8 Replies

4. Shell Programming and Scripting

Searching for files with specific extensions

Hi, Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log. I've tried to use ls *.txt *.log which works if there are both... (4 Replies)
Discussion started by: neilmw
4 Replies

5. Shell Programming and Scripting

Rename files extensions

Hello ! i have a few files like ... setup.001 setup.002 setup.003 setup.004 // to setup.095 and i would like to rename those files to ... setup.r01 setup.r02 setup.r03 setup.r04 // to setup.r95 (7 Replies)
Discussion started by: Putazo
7 Replies

6. UNIX for Dummies Questions & Answers

changing extensions for multiple files at once

I copied some files to another folder, and I want to change them from .doc extensions to .txt extensions. I tried using the cp and mv commands, but it didn't work. Is it possible to change file extensions with these commands, and if so how do I do it? I tried using the * wildcard (say cp *.doc... (1 Reply)
Discussion started by: Straitsfan
1 Replies

7. Shell Programming and Scripting

Sorting Files according to their Extensions...

I am trying to write a Korne Shell Script wherein we have to sort files according to their extensions(for eg. 1.sh, 5.sh, 9.sh together; 4.csh, 120.csh, 6.csh together and 7.ksh, 2.ksh, 59.ksh together) and move them to their respective directories viz. sh, csh and ksh... I think,... (1 Reply)
Discussion started by: marconi
1 Replies

8. Shell Programming and Scripting

Find files with 3 different extensions

Hi all, From one directory I need to fetch only files of type *.xls,*.csv,*.txt. I tried the find . -name '*.txt,*.csv,*.xls' -print. But it throws me error. Please do help me on this. Thanks Mahalakshmi.A (11 Replies)
Discussion started by: mahalakshmi
11 Replies

9. UNIX for Dummies Questions & Answers

List Files by Extensions

I have a unix directory with 500 plus files . When I do a ls -lR I can see ALL the files here . How can I sort this by the files extensions ? I can't enter ls -lR *.ext1 *.ext2 *.ext3 etc in case I miss out some files . (2 Replies)
Discussion started by: newbienix
2 Replies

10. UNIX for Dummies Questions & Answers

Command to select files with different extensions

I want to select files which have different extensions such as .cpp, .cs, .h I can select one of them as find . -name "*.cpp" but I want to select all of them in one command only. It should be pretty simple but I'm not able to get it. Any help with the command will be greatly appreciated. (1 Reply)
Discussion started by: MobileUser
1 Replies
Login or Register to Ask a Question