Following from this question, where I wish to extract 10 random lines from a file, I now wish to also have the remaining 90 lines as a separate file.Since the document has 100 lines, indexing from 1 to 100, the problem boils down tofinding the complement set of ind within 1, 2, ..., 100, whereind=$(shuf -i 1-100 -n 10 | sort -n)So my questions areHow can I generate the array 1, 2, ..., 100 efficiently? andIt seems that this can be done with comm. If so, how should I do comm on arrays (not files)?
Find the complement set of an array?
shell script;text processing;array
Based on my proposal from the other thread:awk '  BEGIN { srand(); do a[int(100*rand()+1)]; while (length(a)<10) }  NR in a' ~/orig.txt > ~/short.txtthis could be changed to create both files:awk -v range=100 -v offset=1 -v amount=10 '  BEGIN { srand(); do a[int(range*rand()+offset)]; while (length(a)<amount) }  NR in a    { print > short.txt }  !(NR in a) { print > rest.txt }' ~/orig.txt(Note that inside awk you cannot use ~. It's possible, though, to use HOME through ENVIRON[], as in: print > ENVIRON[HOME] /short.txt, or resp., print > ENVIRON[HOME] /rest.txt.)