You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
524 B
26 lines
524 B
#!/usr/bin/env bash |
|
|
|
# Add timestamp to each line of the text output as moreutils/ts does. |
|
|
|
rstc="\033[00m" |
|
colour="\033[1;36m" # blue |
|
|
|
usage() { |
|
echo "USAGE: ${0##*/} [-n] [DATE FORMAT]" |
|
echo " e.g. \`ping 127.0.0.1 | ts [%T]'" |
|
} |
|
|
|
for arg in "$@"; do |
|
case "$arg" in |
|
-h) usage; exit 0;; |
|
-n) colour=""; rstc="";; |
|
*) date_fmt="${arg}";; |
|
esac |
|
done |
|
|
|
DATE_FORMAT="${date_fmt:-[%Y-%m-%d %T]}" |
|
|
|
awk -v fmt="$DATE_FORMAT" -v colour="$colour" -v rstc="$rstc" '{ |
|
printf("%s%s%s %s\n", colour, strftime(fmt), rstc, $0) |
|
}' |
|
|
|
|