Last active
July 28, 2018 19:47
-
-
Save gromnitsky/e9b0ac81ca9c84021a0b1970ba1eadbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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