Skip to content

Instantly share code, notes, and snippets.

@gromnitsky
Last active Jul 28, 2018
Embed
What would you like to do?
#!/bin/sh
# -*-coding:utf-8-unix-*-
usage() { echo Usage: ipconfig \| `basename $0` [-v] [-m NUM] pattern 1>&2; exit 2; }
while getopts "vm:" o; do
case $o in
v) opt_v=! ;;
m) opt_m=$OPTARG ;;
*) usage
esac
done
shift $((OPTIND-1))
[ -z "$1" ] && usage
tr -d '\r' \
| sed -E 's/^([^ ].+:)$/~~~\1/' \
| gawk -v opt_m=$opt_m 'BEGIN {IGNORECASE=1; RS="~~~"; ORS=""} '"$opt_v"'/'"$1"'/ {print; m++; if (opt_m == m) exit } END { exit (m == 0) }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment