Answer the question
In order to leave comments, you need to log in
How to generate a fixed string from a number in bash?
you need to output sequentially a string like "A0000".
The question is how to iteratively get a number and make the desired string out of it.
for example: generate from 1 string like "0001".
now I'm doing it with 5 nested loops.... but it doesn't seem like a very pretty way.
#!/bin/bash
allThreads=("B" "C" "D" "F" "G" "H" "J" "K" "L" "M" "N" "P" "Q" "R" "S" "T" "V" "W" "X" "Y" "Z")
echo "INSERT INTO public.audience (audience_name, \"limit\") VALUES "
for ((l = 0 ; l < 10 ; l++)); do
for ((g = 0 ; g < 10 ; g++)); do
for ((k = 0 ; k < 10 ; k++)); do
for ((j = 0 ; j < 10 ; j++)); do
for ((i = 0 ; i < 10 ; i++)); do
audience=${allThreads[$l]}
num=${g}${k}${j}${i}
audience="${audience}${num}"
echo "('${audience}'::varchar(5), `shuf -i1-40 -n1`), "
done
done
done
done
done
echo " ('Z1111'::varchar(5), `shuf -i1-40 -n1`); "
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question