# egrep.awk --- simulate egrep in awk # # Arnold Robbins, arnold@skeeve.com, Public Domain # May 1993 # Options: # -c count of lines # -s silent - use exit value # -v invert test, success if no match # -i ignore case # -l print filenames only # -e argument is pattern # # Requires getopt and file transition library functions BEGIN { while ((c = getopt(ARGC, ARGV, "ce:svil")) != -1) { if (c == "c") count_only++ else if (c == "s") no_print++ else if (c == "v") invert++ else if (c == "i") IGNORECASE = 1 else if (c == "l") filenames_only++ else if (c == "e") pattern = Optarg else usage() } if (pattern == "") pattern = ARGV[Optind++] for (i = 1; i < Optind; i++) ARGV[i] = "" if (Optind >= ARGC) { ARGV[1] = "-" ARGC = 2 } else if (ARGC - Optind > 1) do_filenames++ # if (IGNORECASE) # pattern = tolower(pattern) } #{ # if (IGNORECASE) # $0 = tolower($0) #} function beginfile(junk) { fcount = 0 } function endfile(file) { if (! no_print && count_only) { if (do_filenames) print file ":" fcount else print fcount } total += fcount } { matches = ($0 ~ pattern) if (invert) matches = ! matches fcount += matches # 1 or 0 if (! matches) next if (! count_only) { if (no_print) nextfile if (filenames_only) { print FILENAME nextfile } if (do_filenames) print FILENAME ":" $0 else print } } END { exit (total == 0) } function usage() { print("Usage: egrep [-csvil] [-e pat] [files ...]") > "/dev/stderr" print("\n\tegrep [-csvil] pat [files ...]") > "/dev/stderr" exit 1 }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
alarm.awk | File | 2.31 KB | 0644 |
|
anagram.awk | File | 1.33 KB | 0644 |
|
awksed.awk | File | 515 B | 0644 |
|
cut.awk | File | 3.61 KB | 0644 |
|
dupword.awk | File | 507 B | 0644 |
|
egrep.awk | File | 1.91 KB | 0644 |
|
extract.awk | File | 1.74 KB | 0644 |
|
guide.awk | File | 165 B | 0644 |
|
histsort.awk | File | 283 B | 0644 |
|
id.awk | File | 1.22 KB | 0644 |
|
igawk.sh | File | 3.11 KB | 0644 |
|
indirectcall.awk | File | 952 B | 0644 |
|
labels.awk | File | 1014 B | 0644 |
|
split.awk | File | 1.17 KB | 0644 |
|
tee.awk | File | 770 B | 0644 |
|
testbits.awk | File | 729 B | 0644 |
|
translate.awk | File | 1.15 KB | 0644 |
|
uniq.awk | File | 2.64 KB | 0644 |
|
wc.awk | File | 1.45 KB | 0644 |
|
wordfreq.awk | File | 347 B | 0644 |
|