Skip to content

Instantly share code, notes, and snippets.

@ezr
Created September 22, 2021 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezr/bb651927739abe41d0bd59bb8c031ee0 to your computer and use it in GitHub Desktop.
Save ezr/bb651927739abe41d0bd59bb8c031ee0 to your computer and use it in GitHub Desktop.
Print the supplied format once for each line of stdin
#!/usr/bin/env bash
USAGE=$(cat <<-END
Error: no argument supplied.
This program prints the template once for each line of stdin. It only substitutes one variable in the printf format string.
Usage:
$0 <printf_format> < data
Examples:
$0 'ping -c 1 %s' < hosts
END
)
if [ -z "$1" ]; then
printf "$USAGE\n" "%s"
exit 1
fi
while read line; do
printf "$1\n" "$line"
done < /dev/stdin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment