Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # this script outputs all ip's in a file or from stdout
  4. # pretty handy sometimes. I especially needed something like this
  5. # for some of my other scripts, so I didn't need to type the
  6. # [0-9]{1,3}\.[ ... thing a thousand times.
  7.  
  8. # Usage:
  9. # $ ipgrep [-l] `cat /path/to/file`
  10. # or
  11. # $ cat /path/to/file | ipgrep [-l]
  12.  
  13. # NOT
  14. # $ ipgrep /path/to/file
  15. # You need the cat-command in some way or another.
  16.  
  17. # the -l switch makes all the ip's stand one on each line in stead of all in one line
  18.  
  19. if [ "$1" = "" ] || ( [ "$1" = "-l" ] && [ "$2" = "" ] ) ; then
  20. line=`cat /dev/stdin`
  21. else
  22. line="$@"
  23. fi
  24. ip=`echo "$line" | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
  25.  
  26. if [ "$1" = "-l" ] ; then
  27. for i in $ip ; do
  28. echo $i
  29. done
  30. else
  31. echo $ip
  32. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement