Originally Posted by r_arun
I tried the following thing, but it doesn't get reflected in the file
sed "s:$:\t$(date +%Y-%m-%d):" DW.txt
It doesn't get reflected because sed
, like most commands, doesn't alter the original text by default. It only prints the modified contents to stdout.
The traditional way to handle it is simply to redirect the output to a temporary file, then replace the original with it. (Note that you can't generally use the same file for both input and output.)
gnu sed also has the "-i
" option for editing the file in place. Basically it does all the tempfile work for you transparently behind the scenes.