Files
dotfiles/utils/.local/bin/line
2026-02-21 18:10:09 +08:00

28 lines
501 B
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
cat <<EOF
Usage: $(basename "$0") [-h] <lineno> <file>
Display a specific line from a file.
Options:
-h, --help Show this help message
Arguments:
lineno Line number to display (1-based)
file File to read from
EOF
exit 0
fi
lineno="$1"; shift
if [[ ! -t 0 ]]; then # Read from stdin (pipe)
sed -n "${lineno}p"
else # Read from file
sed -n "${lineno}p" -- "$@"
fi