Con perl:
command 2>&1 | perl -pe 'print scalar(localtime()), " ";'
Con gawk:
command 2>&1 | awk '{ print strftime(), $0; fflush() }'
Sostituisci command
con tail -f logfile
per il tuo esempio specifico. Oppure potresti semplicemente reindirizzare lo stdout/stderr del programma originale alla pipe sopra.
Prova
tail -f logfile | while read line; do echo `date` "$line" ; done
Puoi provare questo
cat /etc/motd | xargs -d"\n" -I {} date +"%Y-%m-%d %H:%M:%S {}"
Esempio di output:
2013-02-26 15:13:57 2013-02-26 15:13:57 The programs included with the Debian GNU/Linux system are free software; 2013-02-26 15:13:57 the exact distribution terms for each program are described in the 2013-02-26 15:13:57 individual files in /usr/share/doc/*/copyright. 2013-02-26 15:13:57 2013-02-26 15:13:57 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent 2013-02-26 15:13:57 permitted by applicable law.