Ok, on second thought - I worked way too hard on that. You just need this:
shuf -i 1-100 -n10 |
sed 's/$/{p;b\n}/' |
sed -nf - -e 'w separate_file' infile >outfile
Though you might need a literal newline in-place of the n
in the sed
substitution. Anyway that does the same as below - it just doesn't bother doing all of the other 90 lines - they just fall into place because they're in the file - so they don't need any special consideration.
Here's the whole deal:
set " $(shuf -i 1-100 -n 10) "
while [ "$((i+=1))" -le 100 ]
do [ -z "${1##*[!0-9]$i[!0-9]*}" ]
printf "$i%.$((!$?))s%.$?s\n" p H
done| sed -nf - -e '$!d;x;s/.//p' <infile >outfile
There - we just basically write a sed
script that looks like:
1H
2H
3H
4p
5H
...
90p
91H
...
And so on through to 100. On the last line - after all of the randomly selected lines have already been p
rinted, we ex
change into H
old space, s///
ubstitute away the first inserted \n
ewline character, and p
rint the lot of the rest.
To do this without the shell loop you could do:
set "$(shuf -i 1-100 -n 10)"
{ seq 100 | grep -Fxv "$1"; echo "$1"; } |
sed '1,90s/$/H/;91,$s/$/p/' |
sed -nf - -e '$!d;x;s/.//p' <infile >outfile
But I'm not sure whether on this scale that would be beneficial at all.
Anyway, I used a seq 100
output file as a test, and after running it through it printed...
3
4
5
19
57
63
64
73
80
88
1
2
6
7
8
9
10
11
12
13
14
15
16
...
...and on through to 100 for all of the lines not included in the initial random 100.
sed
command withd
instead ofp
? – muru May 27 at 17:10d
gives me an empty file – Sibbs Gambling May 28 at 2:24