Advertisement
voyeg3r

randomphrase.sh

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