-1

Here is what I'm trying to do:

-Search for the first item on the austinproductlist.txt file within a folder and all its sub folders

-If the item is found, copy it to the folder on the desktop labeled as "target"

-repeat for every item listed in the .txt file

My attempt using the terminal:

$for i in `cat ~/Desktop/austinproductlist.txt’find ~/desktop/AustinWebImages -type f -name "$i" -exec cp "{}" ~/Desktop/target ;

Response: -bash: syntax error near unexpected token `find'

My AppleScript attempt:

I think the issue is that the command is look for the exact file name but what I need to search for is a string within the file name. If the filename contains that string, I would like to copy it to the folder "target".

Here's a screen shot of my automator attempt: enter image description here

Andy J
  • 1,479
  • 6
  • 23
  • 40
Mittens
  • 11
  • 2

1 Answers1

0

There are only two problems with your script:

1) Your for loop needs do and done.

2) The -exec action needs a backslash at the end (\)

Try:

#!/bin/bash
for i in `~/Desktop/austinproductlist.txt`;
  do find ~/desktop/AustinWebImages -type f -name "$i" -exec cp "{}" target \;
done

In case you're wondering about the trailing backslash; the -exec action takes each command up until the ; which needs to be escaped because shell uses it also, and would otherwise terminate the find command.

Why are the backslash and semicolon required with the find command's -exec option?

Andy J
  • 1,479
  • 6
  • 23
  • 40
  • for some reason the it is now giving me a permission denied for my .txt file... just trying to figure that out now – Mittens Dec 18 '18 at 00:58
  • Can you show the output of `ls -l Desktop/austinproductlist.txt`? – Andy J Dec 18 '18 at 01:31
  • I'm looking for the 10-symbol string showing showing permission rights for that file :). – Andy J Dec 18 '18 at 03:23
  • iMac:~ azfour$ ls -l Desktop/austinproductlist.txt -rw-r--r--@ 1 azfour staff 112 17 Dec 17:12 Desktop/austinproductlist.txt – Mittens Dec 18 '18 at 17:58
  • I have solved the permissions issue but its not moving the images. I think it may be because the text file only contains a string within the images name and not the entire image name. – Mittens Dec 18 '18 at 18:19
  • If you format your input text file one filename per row, with extensions, it will work :). – Andy J Dec 21 '18 at 07:45