Skip to content

Instantly share code, notes, and snippets.

@cybersamx
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybersamx/bc1f8bfc3a0d95c5c298 to your computer and use it in GitHub Desktop.
Save cybersamx/bc1f8bfc3a0d95c5c298 to your computer and use it in GitHub Desktop.
Ways for sed to match and replace lines
# Remove all occurences of string_to_match
sed -i '/string_to_match/d' file
# Match and add new string line
sed -i '/string_to_match/a new_string' file
# Match string and replace the entire line with string line
sed -i '/string_to_match/c\new_string' file
# Match the string and replace with sring
sed -i '/string_to_match/new_string/g' file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment