# randomlines.sh [--verbose] \<FILE> \<COUNT> Prints COUNT lines from FILE randomly ## Usecases You have a list of cities you wish to travel to during your summer holidays but you don't know which ones to visit first. This program for Linux, ***randomlines.sh*** can help you to decide where to go first. It also could be used to randomly elect steemians or posts for a contest. ## Format the Data Put the list in a file. One item, one line. ***towns.csv*** ``` Amsterdam Athens ... Stockholm Vienna ``` ## The command To know the 5 next cities to travel to, just type the command in a terminal: ```bash $ ./randomlines.sh towns.csv 5 ``` It produces the output: ``` Paris Vienna Geneva Monaco Athens ``` ### Verbose Option Unfortunately, it doesn't post the result in the blockchain yet ;) ```bash $ ./randomlines.sh --verbose towns.csv 5 towns.csv has 16 lines Drawing 5 numbers between 1 and 16 Numbers: 12 3 6 10 16 #12 Paris #3 Barcelona #6 Brussels #10 Monaco #16 Vienna ``` https://www.macworld.co.uk/cmsdata/features/3608274/Terminalicon2_thumb800.png # The source code I'm lazy, nevertheless I added comments. ```bash #!/bin/bash # function to print a random number between $1 and $2 randint() { min=$1 max=$2 # modulo let "mod=1+max-min" # big random hex number (16 hex numbers, uppercase) h=$(openssl rand -hex 16 | tr [a-z] [A-Z]) # decimal conversion n=$(echo "ibase=16; $h" | bc) # print the random number echo "($n % $mod) + $min" | bc } # parameters if [[ "$1" == "--verbose" ]] ; then verbose=0 # true shift fi file=$1 todraw=$2 # checks if [[ "$todraw" == "" ]] ; then echo "Usage $0 [--verbose] <FILE> <COUNT>"; exit 1 fi if [ ! -e "$file" ] ; then echo "File $file does not exist" exit 1 fi # limits min=1 max=$(wc -l $file | cut -d\ -f1) if [ $verbose ] ; then echo "$file has $max lines" ; fi if [[ "$todraw" -gt "$max" ]] ; then echo "File $file has too few lines ($max) to draw $todraw distinct items" exit 1 fi # draw distinct random numbers if [ $verbose ] ; then echo "Drawing $todraw numbers between $min and $max" ; fi count=0 numbers="" while [[ "$count" != "$todraw" ]] ; do value=$(randint $min $max) found=$(echo $numbers | egrep "^$value | $value | $value$") if [[ "$found" == "" ]] ; then numbers="$numbers $value" let "count=count+1" fi done if [ $verbose ] ; then echo "Numbers: $numbers" ; fi # print elected lines for number in $numbers ; do if [ $verbose ] ; then echo -n "#$number " ; fi # print the corresponding line of the file sed -n "$number"p $file done exit 0 ``` I hope you'll find it useful. Questions, suggestions and remarks are welcome.
post_id | 81,389,769 |
---|---|
author | droida |
permlink | bash-script-to-make-a-random-selection-of-lines-in-a-file |
category | bash |
json_metadata | {"app":"steempeak\/1.19.0","format":"markdown","tags":["bash","linux","development","neoxian","programming","dev","cli","terminal","random","technology"],"image":["https:\/\/www.macworld.co.uk\/cmsdata\/features\/3608274\/Terminalicon2_thumb800.png"]} |
created | 2019-11-02 00:38:54 |
last_update | 2019-11-02 00:50:12 |
depth | 0 |
children | 8 |
net_rshares | 21,448,092,902,886 |
last_payout | 2019-11-09 00:38:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 3.076 SBD |
curator_payout_value | 3.067 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.120 SBD |
body_length | 2,729 |
author_reputation | 6,341,941,362,400 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
remlaps | 0 | 12,171,936,313 | 100% | ||
kirkins | 0 | 2,568,286,716 | 100% | ||
booster | 0 | 2,513,589,047,775 | 83.33% | ||
theguruasia | 0 | 4,469,553,544 | 50% | ||
drotto | 0 | 12,544,789,360 | 3.13% | ||
droida | 0 | 11,281,807,735 | 100% | ||
appreciator | 0 | 4,782,998,299,901 | 6.14% | ||
boomerang | 0 | 12,749,337,289,741 | 100% | ||
drillith | 0 | 3,347,524,290 | 80% | ||
bluenarcolepsy | 0 | 98,233,507 | 100% | ||
brandonfrye | 0 | 409,573,223,679 | 22.68% | ||
freeupvote | 0 | 0 | 100% | ||
minnowvotes | 0 | 2,032,205,692,980 | 10% | ||
charitybot | 0 | 4,294,027,209 | 100% | ||
nodex | 0 | 4,007,847,721 | 30% | ||
crimo | 0 | 7,906,314,812 | 75% | ||
haccolong | 0 | 59,358,448,019 | 85% | ||
nampvhn | 0 | 935,485,623 | 85% | ||
shunnedscarab55 | 0 | 635,974,120 | 75% | ||
bobnevv | 0 | 186,734,658 | 100% | ||
hoaithu | 0 | 19,353,040,514 | 85% | ||
vnminhanh | 0 | 6,729,952,051 | 85% | ||
steeming-hot | 0 | 0 | 0.01% | ||
curationkiwi | 0 | 8,411,171,513 | 25% | ||
anhvutuan | 0 | 924,834,148 | 85% | ||
vacuity | 0 | 6,662,939,579 | 85% | ||
anhvu | 0 | 7,968,537,168 | 85% | ||
longvu | 0 | 3,198,672,281 | 85% | ||
lht | 0 | 929,236,796 | 85% | ||
remlaps-lite | 0 | 12,773,390,566 | 100% | ||
jakerich | 0 | 24,186,785,356 | 100% | ||
esthersanchez | 0 | 578,846,976 | 40% | ||
johannpiber | 0 | 72,410,186,483 | 12% | ||
joelpugapt | 0 | 1,674,403,304 | 100% | ||
haclong | 0 | 918,896,465 | 85% | ||
ctime | 0 | -2,683,096,904,868 | -83.33% | ||
artmentor | 0 | 52,798,603,515 | 50% | ||
gecit | 0 | 465,821,944 | 100% | ||
forplankton | 0 | 922,500,477 | 85% | ||
joseghr | 0 | 477,258,837 | 100% | ||
coredump | 0 | 5,063,164 | 3% | ||
dicetime | 0 | -109,394,521,722 | -100% | ||
freebot | 0 | 581,263,813 | 100% | ||
lunapark | 0 | 551,724,130 | 100% | ||
quicktrade | 0 | 559,859,087 | 100% | ||
stoudi | 0 | 551,448,946 | 100% | ||
francoispignon | 0 | 560,650,232 | 100% | ||
cresus | 0 | 1,993,160,276 | 100% | ||
gastonlagaffe | 0 | 561,006,979 | 100% | ||
hadaly | 0 | 551,687,004 | 100% | ||
goldfoot | 0 | 551,607,162 | 100% | ||
dotmatrix | 0 | 551,964,677 | 100% | ||
otomo | 0 | 551,527,325 | 100% | ||
botito | 0 | 551,845,796 | 100% | ||
weebo | 0 | 551,329,281 | 100% | ||
freysa | 0 | 551,448,331 | 100% | ||
tobor | 0 | 551,409,748 | 100% | ||
buffybot | 0 | 554,668,310 | 100% | ||
hypnobot | 0 | 555,065,414 | 100% | ||
psybot | 0 | 554,547,174 | 100% | ||
psychobot | 0 | 554,626,589 | 100% | ||
curabot | 0 | 551,369,896 | 100% | ||
elector | 0 | 544,569,554 | 100% | ||
chatbot | 0 | 554,947,308 | 100% | ||
chomps | 0 | 551,567,532 | 100% | ||
quicktrades | 0 | 560,768,682 | 100% | ||
misery | 0 | 562,961,305 | 100% | ||
swissbot | 0 | 560,769,202 | 100% | ||
swissapps | 0 | 560,729,481 | 100% | ||
crimcrim | 0 | 973,522,611 | 75% | ||
neoxiancityvb | 0 | 1,141,073,397,174 | 71.36% | ||
trendovoter | 0 | 222,062,317,315 | 100% | ||
drlobes | 0 | 24,764,402,456 | 100% | ||
jabba666 | 0 | 418,594,189 | 100% | ||
tagflagger | 0 | 0 | -83.33% | ||
frank258 | 0 | 270,447,953 | 100% | ||
panda0v0 | 0 | 469,639,328 | 100% | ||
ewi5000 | 0 | 467,971,667 | 100% | ||
crittez | 0 | -9,297,421 | -10% | ||
villode | 0 | -9,297,421 | -10% | ||
certym | 0 | -9,297,421 | -10% | ||
frityhe | 0 | -9,297,421 | -10% | ||
culiko | 0 | -9,297,421 | -10% | ||
chogre | 0 | -9,297,421 | -10% | ||
juanferi | 0 | -9,297,421 | -10% | ||
catreik | 0 | -9,297,421 | -10% | ||
qadee | 0 | 379,592,492 | 100% | ||
caczhubi | 0 | -9,290,427 | -10% | ||
tridimstroc | 0 | -9,290,120 | -10% | ||
atouir | 0 | -9,290,427 | -10% | ||
viazer | 0 | -9,290,120 | -10% | ||
cpuking | 0 | 531,541,860 | 100% | ||
mardesar | 0 | -9,261,989 | -10% | ||
rylabo | 0 | -8,441,593 | -10% | ||
cirambi | 0 | -9,258,980 | -10% | ||
nedryko | 0 | -9,258,980 | -10% | ||
pomelaz | 0 | -9,258,659 | -10% | ||
hustan | 0 | -9,258,980 | -10% |
**Hello @droida** Thank you for following @haccolong account. As a follower of **@haccolong** this post has been randomly selected and **[upvoted](https://steemit.com/free/@haccolong/get-free-upvote-daily-when-follow-me)** by @hoaithu's Curation Trail. To **earn more** rewards with your Steemit account. Check through some of the ways at **[this post]( https://steemit.com/free/@haccolong/how-to-get-more-rewards-if-earning-rewards-is-difficult-for-you-this-post-is-for-you)**. ##### I will continue with random upvotes in the future & wish you lots of luck. :)
post_id | 81,391,155 |
---|---|
author | hoaithu |
permlink | q0blec |
category | bash |
json_metadata | {"users":["droida","haccolong","hoaithu"],"links":["https:\/\/steemit.com\/free\/@haccolong\/get-free-upvote-daily-when-follow-me","https:\/\/steemit.com\/free\/@haccolong\/how-to-get-more-rewards-if-earning-rewards-is-difficult-for-you-this-post-is-for-you"],"app":"steemit\/0.1"} |
created | 2019-11-02 02:25:27 |
last_update | 2019-11-02 02:25:27 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-09 02:25:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 564 |
author_reputation | 4,342,879,484,296 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 0 |
You got voted by @curationkiwi thanks to droida! This bot is managed by [KiwiJuce3](https://bit.ly/2HQOvIO) and run by [Rishi556](https://bit.ly/2OmBsQF), you can check both of them out there. To receive upvotes on your own posts, you need to join the [Kiwi Co. Discord](https://bit.ly/2U8Mo9M) and go to the room named #CurationKiwi. Submit your post there using the command "!upvote (post link)" to receive upvotes on your post. CurationKiwi is currently supported by donations from users like you, so feel free to leave an upvote on our posts or comments to support us! We have also recently added a new whitelist feature for those who would like to support CurationKiwi even more! If you would like to receive upvotes more than 2x greater than the normal upvote, all you need to do is delegate 50 SP to @CurationKiwi using [this link](https://app.steemconnect.com/sign/delegateVestingShares?account=curationkiwi&delegatee=curationkiwi&vesting_shares=99572.000000%20VESTS).
post_id | 81,402,516 |
---|---|
author | curationkiwi |
permlink | re-bash-script-to-make-a-random-selection-of-lines-in-a-file |
category | bash |
json_metadata | {"app":"Discord"} |
created | 2019-11-02 13:56:03 |
last_update | 2019-11-02 13:56:03 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-09 13:56:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 977 |
author_reputation | 2,747,191,214,125 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
<p>This post has received a 3.13 % upvote from @drotto thanks to: @curationkiwi.</p>
post_id | 81,402,558 |
---|---|
author | drotto |
permlink | re-droida-bash-script-to-make-a-random-selection-of-lines-in-a-file-20191102t135804306z |
category | bash |
json_metadata | {"tags":["bash"],"app":"drotto\/0.0.5pre2"} |
created | 2019-11-02 13:58:03 |
last_update | 2019-11-02 13:58:03 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-09 13:58:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 85 |
author_reputation | 424,402,347,817 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
This post has received a 100.0 % upvote from @boomerang.
post_id | 81,413,680 |
---|---|
author | boomerang |
permlink | re-bash-script-to-make-a-random-selection-of-lines-in-a-file-20191102t234748 |
category | bash |
json_metadata | {} |
created | 2019-11-02 23:47:48 |
last_update | 2019-11-02 23:47:48 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-09 23:47:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 56 |
author_reputation | 3,467,368,504,525 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
You got a 10.00% upvote from @minnowvotes courtesy of @droida!
post_id | 81,419,061 |
---|---|
author | minnowvotes |
permlink | re-droida-bash-script-to-make-a-random-selection-of-lines-in-a-file-20191103t055847201z |
category | bash |
json_metadata | {"app":"postpromoter\/2.1.1"} |
created | 2019-11-03 05:58:48 |
last_update | 2019-11-03 05:58:48 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-10 05:58:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 63 |
author_reputation | -300,453,853,020 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
!trendovoter 100
post_id | 81,482,166 |
---|---|
author | theguruasia |
permlink | re-droida-q0hx7h |
category | bash |
json_metadata | {"tags":["bash"],"app":"steempeak\/1.19.0"} |
created | 2019-11-05 12:26:06 |
last_update | 2019-11-05 12:26:06 |
depth | 1 |
children | 1 |
net_rshares | 9,266,534,663 |
last_payout | 2019-11-12 12:26:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 16 |
author_reputation | 59,186,440,518,630 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
droida | 0 | 9,266,534,663 | 100% |
Thanks
post_id | 81,489,723 |
---|---|
author | droida |
permlink | re-theguruasia-q0ibgy |
category | bash |
json_metadata | {"tags":["bash"],"app":"steempeak\/1.19.0"} |
created | 2019-11-05 17:34:09 |
last_update | 2019-11-05 17:34:09 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-12 17:34:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 6 |
author_reputation | 6,341,941,362,400 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
Congratulations @theguruasia, <b>100%</b> upvote has been shared with your successful call on the post that shared by @droida! --- <sup>Support <b>@trendotoken</b> projects by delegating : <b>[100SP](https://beta.steemconnect.com/sign/delegateVestingShares?delegator=YOURUSERNAME&delegatee=trendovoter&vesting_shares=100.000%20SP)</b> , <b>[200SP](https://beta.steemconnect.com/sign/delegateVestingShares?delegator=YOURUSERNAME&delegatee=trendovoter&vesting_shares=200.000%20SP) , <b>[500SP](https://beta.steemconnect.com/sign/delegateVestingShares?delegator=YOURUSERNAME&delegatee=trendovoter&vesting_shares=500.000%20SP)</b> , <b>[1000SP](https://beta.steemconnect.com/sign/delegateVestingShares?delegator=YOURUSERNAME&delegatee=trendovoter&vesting_shares=1000.000%20SP)</b> , <b>[2000SP](https://beta.steemconnect.com/sign/delegateVestingShares?delegator=YOURUSERNAME&delegatee=trendovoter&vesting_shares=2000.000%20SP)</b></sup>
post_id | 81,482,175 |
---|---|
author | trendovoter |
permlink | re-droida-bash-script-to-make-a-random-selection-of-lines-in-a-file-20191105t122620881z |
category | bash |
json_metadata | {"tags":["trdo","newssteem"],"app":"trdo-voter\/1.0","format":"markdown"} |
created | 2019-11-05 12:26:21 |
last_update | 2019-11-05 12:26:21 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2019-11-12 12:26:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 938 |
author_reputation | 60,565,069,820 |
root_title | "Bash Script to Make a Random Selection of Lines in a File" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |