Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #!/usr/bin/env sh
  2. # Prints a random line from a file
  3. # Script by @augustohp
  4.  
  5. lines_on() {
  6. file=$1
  7. wc -l $file | awk '{print $1}'
  8. }
  9. random_until() {
  10. max=$1
  11. min=1
  12. echo $(( ($RANDOM % $max) + $min ))
  13. }
  14. print_line_in_file() {
  15. file=$1
  16. line=$2
  17. awk "NR==${line}" $file
  18. }
  19. if [ -z "$1" ]
  20. then
  21. echo "Usage: $0 <file>"
  22. exit 2
  23. fi
  24. # Here be dragons
  25. print_line_in_file $1 $(random_until $(lines_on $1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement