code-snippets/shell/random-line.sh

7 lines
211 B
Bash
Raw Normal View History

2024-04-08 18:35:01 -04:00
#!/bin/bash
# Output the line of a random even number and the line next before it
number=$((1 + RANDOM % $(expr $(cat filename | wc -l) / 2)))
finalline=$(($number * 2))
head -n $finalline filename | tail -n 2