Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # this script outputs all ip's in a file or from stdout
- # pretty handy sometimes. I especially needed something like this
- # for some of my other scripts, so I didn't need to type the
- # [0-9]{1,3}\.[ ... thing a thousand times.
- # Usage:
- # $ ipgrep [-l] `cat /path/to/file`
- # or
- # $ cat /path/to/file | ipgrep [-l]
- # NOT
- # $ ipgrep /path/to/file
- # You need the cat-command in some way or another.
- # the -l switch makes all the ip's stand one on each line in stead of all in one line
- if [ "$1" = "" ] || ( [ "$1" = "-l" ] && [ "$2" = "" ] ) ; then
- line=`cat /dev/stdin`
- else
- line="$@"
- fi
- ip=`echo "$line" | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
- if [ "$1" = "-l" ] ; then
- for i in $ip ; do
- echo $i
- done
- else
- echo $ip
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement