Skip to content

Instantly share code, notes, and snippets.

@gromnitsky
Last active July 28, 2018 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gromnitsky/e9b0ac81ca9c84021a0b1970ba1eadbb to your computer and use it in GitHub Desktop.
Save gromnitsky/e9b0ac81ca9c84021a0b1970ba1eadbb to your computer and use it in GitHub Desktop.
#!/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