0

I've got a script that takes all files with extension of .123 Some of them start with ABC others start with XYZ. I want to take all the files that have XYZ in the PREFIX and move them to a different directory.
For example, XYZothertext.123 and ABCothertext.123 both come in to a directory /test I want to evaluate if any file contains XYZ in the name and if so, move it to /TEMP instead of /test. AND delete from original folder.

if grep -q XYZ "$*.123"; then
   mv *.ABC /TEMP
fi

This is probably terribly incorrect. But I'm learning.

Jotne
  • 40,548
  • 12
  • 51
  • 55
  • 1
    So what's the question? It sounds like you need to take a look up how to do an if statement in your chosen scripting language. Do you have any existing code written that you can share with us? – skrrgwasme Sep 12 '14 at 15:57
  • You are looking for the glob pattern `XYZ*.123` – glenn jackman Sep 12 '14 at 16:23
  • Scott, The rest of the script was written by a pro...I'm just adding to the code with this attempt. I understand if statements in theory, and can pick apart what they are typically doing. The question is, can someone share an example of how to write this (in KSH)? I often learn by example and reverse engineering. – Bryan-A Sep 12 '14 at 18:14
  • I've written this thus far: ### Check for UB9 files and move to /ub835 if found cd $ub9dir if grep -q UB9* "$*.835"; then mv UB9* /UB9Files fi – Bryan-A Sep 12 '14 at 18:45
  • `grep` is for matching patterns on its input or in file content, not for matching file names. You want a glob as @glennjackman said. Your command will look something like `mv XYZ*.123 /TEMP`. If you need to do it recursively then you may want `find` instead. – ormaaj Sep 14 '14 at 15:02

1 Answers1

0
mv XYZ*123 /TEMP
mv ABC*123 /test
Walter A
  • 19,067
  • 2
  • 23
  • 43