## Generate sequences of numbers

# 1 to 10
seq 10

# From 5 to 15
seq 5 15

# Count in steps of 5
seq 0 5 100

# Count down
seq 10 -1 1

# Decimal steps
seq 0 0.5 3

# Pad with leading zeros to equal width
seq -w 1 100

# Zero-padded to a fixed width with a format
seq -f '%03g' 1 20

# Add a prefix with a format string
seq -f 'web%g' 1 5

# Custom separator instead of a newline
seq -s, 1 10

# Space-separated
seq -s' ' 1 10

# All on one line with no separator issues
seq 1 10 | paste -sd,

# Loop a fixed number of times
for i in $(seq 1 5); do echo "run $i"; done

# The shell's own range, which needs no subprocess
for i in {1..5}; do echo "run $i"; done

# Brace range with a step
for i in {0..100..10}; do echo "$i"; done

# Loop when the bound is in a variable (brace expansion will not expand it)
for i in $(seq 1 "$count"); do echo "$i"; done

# A C-style loop, often clearest for variables
for ((i = 1; i <= count; i++)); do echo "$i"; done

# Create numbered files
seq -w 1 10 | xargs -I{} touch "file-{}.txt"

# Create numbered directories
seq -f 'day-%02g' 1 31 | xargs mkdir -p

# Generate a list of hostnames
seq -f 'web%g.example.com' 1 5

# Ping a range of addresses
seq 1 254 | xargs -P32 -I{} ping -c1 -W1 "192.168.1.{}" > /dev/null 2>&1

# Generate a range of ports to test
seq 8000 8010 | xargs -I{} nc -z -w1 localhost {}

# Sum the numbers 1 to 100
seq 1 100 | paste -sd+ | bc

# Sum with awk
seq 1 100 | awk '{s += $1} END {print s}'

# Average
seq 1 100 | awk '{s += $1; n++} END {print s / n}'

# Generate test data
seq 1 1000000 > numbers.txt

# Generate a CSV with an index column
seq 1 10 | awk '{print $1 "," "item" $1}'

# Repeat a command N times in parallel
seq 1 20 | xargs -P4 -I{} ./worker.sh {}

# Retry a command a few times
for i in $(seq 1 3); do ./flaky.sh && break; sleep 2; done

# A progress bar of dots
seq 1 20 | while read -r _; do printf '.'; sleep 0.1; done; echo

# Shuffle a range instead of listing it in order
seq 1 100 | shuf | head -n 5

# Pick one random number in a range
seq 1 100 | shuf -n 1

# Reverse a sequence
seq 10 | tac

# Every other number
seq 1 2 20

# Count lines a sequence produces, as a sanity check
seq 0 5 100 | wc -l
