Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Filename: getphrase.sh
- # Created: 2019-05-24 07:33
- # Last Change: mai 24 2019 08:23
- # Author: Sérgio Araújo - voyeg3r at gmail
- # PRINT A RANDOM PARAGRAPH FROM A GIVEN FILE
- # I have a file called phrases were I collect phrases in English
- # that I am learning and I had the crazy idea of getting on random phrase
- # This script will get a random phrase (the criteria is: paragraphs separated by blank lines)
- # target file
- file=~/.dotfiles/nvim/wiki/phrases.md
- # count registers
- COUNT=$(awk 'BEGIN {RS="";FS="\n"} {print NR}' $file | tail -1)
- # print a random number: shuf -i 1-10 -n 1
- # from the third phrase (the first two are explanatory of the file)
- # the last line contains tags, nor a real phrase so I have to get
- # from the third paragraph to the end minus one
- RANDPHRASE=$(shuf -i 3-$((COUNT -1)) -n 1)
- clear
- echo "phrase number: $RANDPHRASE"
- echo
- awk -v number=$RANDPHRASE 'BEGIN {RS="";FS="\n"} NR==number' $file
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement