Skip to content

Instantly share code, notes, and snippets.

@shamangeorge
Last active December 25, 2015 23:29
Show Gist options
  • Save shamangeorge/7057733 to your computer and use it in GitHub Desktop.
Save shamangeorge/7057733 to your computer and use it in GitHub Desktop.
Useful bash regexp methods
egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' # finds ips in a file
# From http://stackoverflow.com/questions/1444406/how-can-i-delete-duplicate-lines-in-a-file-in-unix/1444448#1444448
# delete duplicate, consecutive lines from a file (emulates "uniq").
# First line in a set of duplicate lines is kept, rest are deleted.
sed '$!N; /^\(.*\)\n\1$/!P; D'
# delete duplicate, nonconsecutive lines from a file. Beware not to
# overflow the buffer size of the hold space, or else use GNU sed.
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment