Skip to content

Instantly share code, notes, and snippets.

@jasimmonsv
Last active June 27, 2022 21:54
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 jasimmonsv/dee4c7304c0c29d6601f125d9365a270 to your computer and use it in GitHub Desktop.
Save jasimmonsv/dee4c7304c0c29d6601f125d9365a270 to your computer and use it in GitHub Desktop.
SED URL and IP defang
# replaces IP addresses with brackets around `.` :: 192[.]168[.]1[.]42
s/\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)/\1[.]\2[.]\3[.]\4/g
# replaces all http(s) instances with hxxp(s)
s/http/hxxp/g
@jasimmonsv
Copy link
Author

jasimmonsv commented Jun 27, 2022

sed -f ./defang.sed ./<file_name> will output URLs and IP addresses as: 192[.]168[.]1[.]10 and hxxps://google.com

@jasimmonsv
Copy link
Author

\( - sed beginning of lookup group
[0-9] - range of numbers between 0-9
\{1,\} - One or more instance of previous lookup
\) - sed close of lookup group
\1 - sed reference to first lookup group
\2 - sed reference to second lookup group... etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment