2 changed files with 27 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||||||
|
#!/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) |
||||||
|
}' |
||||||
|
|
Loading…
Reference in new issue