Skip to content

Instantly share code, notes, and snippets.

@alanhoyle
Created May 10, 2022 22:23
Show Gist options
  • Save alanhoyle/80fef560c91ed40f48f2fb41f2ab2e02 to your computer and use it in GitHub Desktop.
Save alanhoyle/80fef560c91ed40f48f2fb41f2ab2e02 to your computer and use it in GitHub Desktop.
Insert line in file and keep timestamp
temp_file=$(mktemp)
touch -r $1 $temp_file
sed -i '/^.*put something above me.*/i text_to_be_inserted' $1
touch -r $temp_file $1
rm $temp_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment