#!/usr/bin/awk -f # Usage: pgrep.awk [source file]] # # search - search string # source_file - (optional) the source file which will be searched # # Base - 2007/08/28 by Stanley HC Lan BEGIN { RS=""; FS="\n"; ORS="\n\n"; OFS="\n"; if (ARGC < 2) { print "Usage: pgrep.awk [target file]"; exit } else { if (ARGC > 2) { search=ARGV[1] target_file=ARGV[2] delete ARGV[1] delete ARGV[2] } else { search=ARGV[1] delete ARGV[1] } ARGV[1]=target_file } } $0 ~ search { print; a++ }