code-snippets/shell/random-line.sh

7 lines
211 B
Bash

#!/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