Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active August 22, 2018 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/cfd543d2fb68eb2f14c3f02d14f64226 to your computer and use it in GitHub Desktop.
Save Integralist/cfd543d2fb68eb2f14c3f02d14f64226 to your computer and use it in GitHub Desktop.
[Sed Ignore Lines] #sed #ignore #regex #patterns
# imagine you have multiple lines (non-deterministically generated):
#
# server 127.0.0.1; other stuff
# server 127.2.2.2:2222; other stuff
#
# to replace the second line and not the first, you can use the /.../! syntax
# this says "as long as the first pattern doesn't match, go ahead and try the substitution"
#
# sed -i '/some_pattern_to_ignore/! s/some_pattern_to_match/the_replacement_for_the_match/g' /nginx.conf
sed -i '/server 127.0.0.1/! s/server [^:]\+:[^;]\+/server 127.0.0.1:9000/g' /nginx.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment