Last active
December 25, 2015 23:29
-
-
Save shamangeorge/7057733 to your computer and use it in GitHub Desktop.
Useful bash regexp methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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