[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sequence Brace Expansion Crash
From: |
Greg Wooledge |
Subject: |
Re: Sequence Brace Expansion Crash |
Date: |
Mon, 4 Jun 2018 09:02:33 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Sat, Jun 02, 2018 at 09:18:14PM -0700, Thomas Fischer wrote:
> Repeat-By:
> echo {a..z}{a..z}{a..z}{a..z}{a..z}{a..z}
26^6 = 308915776 words of 6 bytes each, plus however much overhead is
involved in constructing a list of 308915776 strings.
You've probably gone well over 2 GB of virtual memory for this expansion.
When you're trying to a few GB of data to stdout, use nested loops
instead of a single brace expansion that needs to generate the entire
list in memory.
for a in {a..z}; do
for b in {a..z}; do
for c in {a..z}; do
for d in {a..z}; do
for e in {a..z}; do
for f in {a..z}; do
printf '%s%s%s%s%s%s\n' "$a" "$b" "$c" "$d" "$e" "$f"
done
done
done
done
done
done
And if that's too slow in bash, consider using awk or perl or C.