GREP/FIND IPS IN A FILE
########################

CITATION: http://www.unix.com/shell-programming-scripting/185469-grep-ip-address-file.html

*** ANSWER – FIND IPS ANYWHERE IN A FILE (valid ips as i understand) – puts its finds on a new line – BEST ONE ***:

 

TO JOIN LINES THAT ARE SEPERATED BY NEWLINES INTO A SINGLE LINE – SPACE SEPERATED JOIN:
cat file | xargs

TO JOIN LINES THAT ARE SEPERATED BY NEWLINES INTO A SINGLE LINE – COMMA SEPERATED JOIN:
cat file | xargs | sed -e ‘s/ /, /g’

*** ANSWER (SINGLE LINE, SPACE SEPERATED) – THE BEST METHOD FROM ABOVE WITH JOINING TO SINGLE LINE ADDITION ***:

 

*** ANSWER (SINGLE LINE OUTPUT, COMMA SEPERATED) – THE BEST METHOD FROM ABOVE WITH JOINING TO SINGLE LINE ADDITION ***:

 

— BAD ANSWER – FIND IPS THAT START A LINE IN A FILE (valid ips as i understand) – not as good one —:
‘^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$’
example1:
———-

IMAGINE THIS FILE (IPS THAT START IN A LINE, OR BEGIN IN THE LINE BUT NOT IN THE START OFTHE LINE)

 

 

**** FIND IPS ANYWHERE **** <— BEST ONE

 

example2:
———-

 

THIS ONE ONLY FINDS IPS IF THE LINE STARTS WITH THEM (not as good one)

 

**** FIND IPS ANYWHERE **** <— BEST ONE – amazing how it found the only correct ones, and even if they are seperated by a comma

 

**** FIND IPS ANYWHERE, and output to a new line comma seperated ****

example3:
———-

FIND ALL OF THE IPS USING YOUR SYSTEM (ips listed more then once with multiple sessions only list their ip once with this script):

 

SINGLE LINE OUTPUT (join output with commas using paste)

 

NOTE: bash navigating the cursor big lines:

control-a: to start
control-e: to end
alt-b: back a word
alt-f: forward a word

Leave a Reply

Your email address will not be published. Required fields are marked *