In general, do use this syntax:
sed "s/<expression>/$(command)/" file
This will look for <expression>
and replace it with the output of command
.
For your specific problem, you can use the following:
sed "s/0/$(date +%s)/g" input.txt > output.txt
This replaces any 0
present in the file with the output of the command date +%s
. Note you need to use double quotes to make the command in $()
be interpreted. Otherwise, you would get a literal $(date +%s)
.
If you want the file to be updated automatically, add -i
to the sed command: sed -i "s/...
. This is called in-place editing.
Test
Given a file with this content:
<?php return 0;
Let's see what it returns:
$ sed "s/0/$(date +%s)/g" file
<?php return 1372175125;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…