algalg
algalg

Reputation: 821

Iterating an unusual incremental stepping pattern of numbers in a bash loop

I have some IDs that follow this unusual incremental stepping pattern, as follows:

eg600100.etc
eg600101.etc
eg600102.etc
...
eg600109.etc
eg600200.etc
...
eg600209.etc
eg600300.etc
...
eg600909.etc
eg601000.etc
eg601001.etc
...
eg601009.etc
eg601100.etc
...
eg601200.etc
...
eg601909.etc

As far as I can tell, it's broken up like this:

60|01-19|00-09

I'm wanting to build a loop that can iterate over each potential ID incrementally up to the end of the range (which is 601909).

How do I break the number up into those 3 segments to manage the unusual stepping for a loop?

I've looked at seq, but I can't figure out how to make it accept the unusual stepping here so that it does not give me numbers between increments that do not exist as potential IDs as above.

#!/bin/bash
for id in $(seq -w 601909)
do
  echo "Testing current ID, which is eg$id.etc"
done

Any ideas?

Upvotes: 0

Views: 43

Answers (1)

vintnes
vintnes

Reputation: 2030

Try using Brace Expansion:

printf %s\\n eg60{01..19}{00..09}.etc >file

Run this as a test, but you can iterate over such an expansion:

for id in eg60{01..19}{00..09}.etc; do echo Testing ID: $id; done

Upvotes: 2

Related Questions