Here's my sed-in-place helper function that preserves modification and creation timestamps. It's pure POSIX shell script and works in BusyBox / AlpineLinux.
sednomodtime() (
_SEDFILE="$1"SEDFILE="$1"
shift
TMPFILE="$(mktemp -- "$SEDFILE.XXXXXX")" &&\
sed "$@" <"$_SEDFILE"<"$SEDFILE" >"$_SEDFILE.new">"$TMPFILE" &&\
touch -r "$_SEDFILE""$SEDFILE" "$_SEDFILE.new""$TMPFILE" &&\
mv -f "$_SEDFILE.new""$TMPFILE" "$_SEDFILE""$SEDFILE"
)
For example usage, one of my Linux kernel modifications is:
sednomodtime fs/pstore/inode.c -Ee 's/CONFIG_PSTORE_DEFAULT_KMSG_BYTES/10240/g'