cp RAW files if JPEG file present


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cp RAW files if JPEG file present
# 1  
Old 04-10-2011
cp RAW files if JPEG file present

hi guys and girls,

i have a folder containing RAW and JPG images. eg...

001.jpg
003.jpg
005.jpg

001.raw
002.raw
003.raw
004.raw
005.raw



I want to copy only RAW files that have a corresponding JPG file in to a new folder. the jpg files do not need to be copied.

in this example i need to copy

001.raw
003.raw
005.raw


in to a subfolder.


i have thousands RAW and JPG images and i do not have patience to do this manually Smilie

please help.
# 2  
Old 04-10-2011
Run it in the directory containing image files:
Code:
ls *.jpg | perl -lne 's/\..*//;system "cp $_.raw /copy/where"'

Change the red part to the path that you want your files to be copied to.
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 04-10-2011
Code:
ls *.jpg *.raw |
awk -F'.'  ' arr[$1]++ 
             END {for (i in arr) { if(arr[i]==2) {print i ".raw ./subdirectory" } ' > filecpy
chmod +x filecpy
# review what is in the filecpy file before you do this next step
./filecpy

# 4  
Old 04-10-2011
Quote:
Originally Posted by bartus11
Run it in the directory containing image files:
Code:
ls *.jpg | perl -lne 's/\..*//;system "cp $_.raw /copy/where"'

Change the red part to the path that you want your files to be copied to.

thank you for the prompt reply, will try that when i get home and let you know how it went Smilie

---------- Post updated at 02:09 PM ---------- Previous update was at 02:08 PM ----------

thank you jim, i will try your suggestion too, much appreciated.

Quote:
Originally Posted by jim mcnamara
Code:
ls *.jpg *.raw |
awk -F'.'  ' arr[$1]++ 
             END {for (i in arr) { if(arr[i]==2) {print i ".raw ./subdirectory" } ' > filecpy
chmod +x filecpy
# review what is in the filecpy file before you do this next step
./filecpy

# 5  
Old 04-10-2011
Run the below command from the dir containing jpg and raw files
Code:
find . -maxdepth 1 -name "*.jpg" -o -name "*.raw" | sort |awk -F"[/.]" '/jpg/{j[$3]++;next} j[$3]{print "cp ",$0," ./subdir/"}' | while read line; do $line; done

# 6  
Old 04-10-2011
Code:
for f in *.raw; do
        [ -f "${f%raw}"jpg ] && cp "$f" subdir
done

Regards,
Alister
# 7  
Old 04-10-2011
Quote:
Originally Posted by bartus11
Run it in the directory containing image files:
Code:
ls *.jpg | perl -lne 's/\..*//;system "cp $_.raw /copy/where"'

Change the red part to the path that you want your files to be copied to.
bartus11 that worked a treat, thank you.

thanks to all the other guys who contributed too, unfortunately the otherscripts did not work. i think i may have made a mistake with the other scripts.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move files only if no other file is present there in first place

Hi, I am not that good in writing shell scripts. I need your help. I have a lot of files which need to moved to another directory but I can do it only if there are no files present there in the first place. I have an auto delete present to delete files from the destination Directory but still I... (5 Replies)
Discussion started by: Crazy_Nix
5 Replies

2. Shell Programming and Scripting

How to copy all the contents of a list of files present in a folder to a particular file?

Hi All, I want to copy all the contents of a list of files in a folder to a particular file. i am using following command: cat dir/* >> newFile.txtIt's not working. Could you please help? Thanks, Pranav (3 Replies)
Discussion started by: Pranav Bhasker
3 Replies

3. Shell Programming and Scripting

compare 2 files and extract the data which is not present in other file with condition

I have 2 files whose data's are as follows : fileA 00 lieferungen 00 attractiop 01 done 02 forness 03 rasp 04 alwaysisng 04 funny 05 done1 fileB alwayssng dkhf fdgdfg dfgdg sdjkgkdfjg funny rasp (7 Replies)
Discussion started by: rajniman
7 Replies

4. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

5. Shell Programming and Scripting

renaming jpeg files

Hi guys im currently trying to write a script which includes rename files and this is the part where i fail i have a list of files eg and i want to rename them so any help really would be appreciated Cheers dunryc (7 Replies)
Discussion started by: dunryc
7 Replies

6. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

7. Shell Programming and Scripting

Script to find all the files that contain any of the words present in another file

Hi All, I am new to UNIX and shell scripts and also new to this forum. I need a script to find all the files in a directory that contain any of the strings present in another file. Please provide me the script or if you could provide pointers to any link in this forum it would be helpful.... (4 Replies)
Discussion started by: tsanthosh
4 Replies
Login or Register to Ask a Question