Share & learn

Through Innovative Digital Library

How to insert date and time at the beginning of each line in file by using sed command?

How to insert date and time at the beginning of each line in file by using sed command?
 



Answers

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).

# cat install.log | sed -e "s/^/$(date -R)/" >> output.log
# less output.log
Answer Question

Your email address will not be published. Required fields are marked *

  • Minimum 20 character
P65V

related questions

Most liked questions

Most answered questions

Login
P65V Refresh
Register
P65V Refresh
Forgot password
Ask a Question
Minimum 20 character
Minimum 20 character
Reply
Minimum 20 character
P65V Refresh