0

I am trying to loop through a series of files and modify them. The files follow a pattern but I can't use pattern because I don't need all the files that match a pattern but just those between a certain sequence of numbers.

Example:

for files in D70_3113.NEF...D70_3330.NEF;do exiftool -GPS...; done
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141

2 Answers2

2

If you want to loop through the list of numbers, you can use a brace expansion:

for files in D70_{3113..3330}.NEF; do exiftool -GPS...; done
Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
0

It depends on what you can expect from your naming scheme. I can't tell if your files can range from

D70_3113.NEF to D79_9999.NEF

or

D70_3113.NEF to D70_3999.NEF

or what have you. Assuming the latter, you could do:

for files in D70_3[0-9][0-9][0-9].NEF; do exiftool -GPS...; done

...just let the shell's pattern matching do the job for you.

Caveat: If you have too many files, the "for" command line may be too long. In that case you'd need to do find and pipe its output into a "while" loop. But today's command lines can run quite long... over 100,000 characters. See Bash command line and input limit

Community
  • 1
  • 1
Mike S
  • 1,235
  • 12
  • 19
  • But that seems like it will include D70_3000.NEF which should not be included and neither should D70_3331.NEF or higher. – Rob Campbell Oct 23 '14 at 02:46
  • Yes, you're right. Generally I prefer to do pattern matching because it will only return the filenames that it finds. Then I don't have to do any extra checking. But here, Tom's answer is what you're looking for. But you should be careful because it will return a set of strings and if you don't have a guarantee that there are no gaps in the filename sequence, you may end up with errors trying to read nonexistent files. A simple test for existence in his for loop will give you an added measure of safety, if you need it. – Mike S Oct 24 '14 at 14:41