ambevar-dotfiles/.scripts/prepend

20 lines
326 B
Plaintext
Raw Normal View History

#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
2013-10-23 12:37:56 +02:00
Usage: ${0##*/} STRING [FILES]
Prepend STRING to FILES or stdin if unspecified. STRING may not contain pipes
('|').
EOF
exit
fi
VAR="$1"
shift
2013-10-23 12:37:56 +02:00
[ $# -eq 0 ] && OPT_INPLACE="" || OPT_INPLACE="-i"
sed -n $OPT_INPLACE '1{s|^|'$VAR'\n|;h};1!H;${x;p}' "$@"