How to insert date and time at the beginning of each line in file by using sed command?
Posted by chandu on December 11th 2017 07:53 AM
1. cat reads file called input.log and just prints it to its standard output stream. Normally the standard output is connected to a terminal, but this little script contains | so shell redirects the standard output of cat to standard input of sed. 2. sed reads data (as cat produces it), processes it (according to the script provided with –e option) and then prints it to its standard output. The script "s/^/$(date -R) /" means replace every start of line to a text generated by date -R command (the general construction for replace command is: s/pattern/replace/). 3. Then according to >> bash redirects the output of sed to a file called output.log (>means replace file contents and >> means append to the end).