Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / share / doc / gawk / examples / prog / | server ip : 172.67.156.115 your ip : 172.70.179.71 H O M E |
Filename | /usr/share/doc/gawk/examples/prog/egrep.awk |
Size | 1.93 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:55 |
Last modified | 29-Mar-2012 04:03 |
Last accessed | 08-Jul-2025 06:16 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
# egrep.awk --- simulate egrep in awk
#
# Arnold Robbins, [email protected], 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 \
{
if (total == 0)
exit 1
exit 0
}
function usage( e)
{
e = "Usage: egrep [-csvil] [-e pat] [files ...]"
e = e "\n\tegrep [-csvil] pat [files ...]"
print e > "/dev/stderr"
exit 1
}
#
# Arnold Robbins, [email protected], 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
}
}
END \
{
if (total == 0)
exit 1
exit 0
}
function usage( e)
{
e = "Usage: egrep [-csvil] [-e pat] [files ...]"
e = e "\n\tegrep [-csvil] pat [files ...]"
print e > "/dev/stderr"
exit 1
}