# filename: paragrep.awk # author: Eric Pement # date: March 23, 2002 # # purpose: awk script displays a paragraph if the search expression # occurs anywhere in the paragraph. Each paragraph must be # separated from other paragraphs like a fully blank line. # # syntax: awk -v search="regex" -f d:\bat\lib\parag.awk myfile # # where 'regex' is any valid awk regular expression. However, # interval expressions like \{4,9\} are not supported without # an additional switch, --re-interval on the command line. BEGIN { RS=""; FS="\n"; ORS="\n\n"; OFS="\n"; # set paragraph mode if (search == "") {print "\aNo search term! Exiting..."; exit 1} } $0 ~ search { print; a++ } END { if (search=="") exit 1 printf ("=============\nSearch matched %s times.\n", a+0 ) printf ("The expresssion to search for was [%s].\n", search) } #---end of script---