Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active August 23, 2022 05:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/62c04977f62037285772 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/62c04977f62037285772 to your computer and use it in GitHub Desktop.
BASH: Sed Simple Literal Text Search & Replace (does not support new lines)
function sed-keyword-escape {
echo $1 | sed -e 's/[]\/$*.^|[]/\\&/g'
}
function sed-replace-escape {
echo $1 | sed -e 's/[\/&]/\\&/g'
}
function sed-easy {
sed -i "s/$(sed-keyword-escape $1)/$(sed-replace-escape $2)/g" $3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment