match(string, regexp)
{
if ($1 == "FIND")
regex = $2
else {
where = match($0, regex)
if (where) {
print "---------------------------------"
print "Match of", regex, "found at", where, "in", $0
print "RSTART variable is " RSTART
print "RLENGTH variable is " RLENGTH
}
}
}
# cat match.txt
FIND g.*d
welcome to groad forum.
Join it and share your ideas!
FIND m.*y
hello linux world.
groad is a forum mainly for linux.
# awk -f match.awk match.txt
---------------------------------
Match of g.*d found at 12 in welcome to groad forum.
RSTART variable is 12
RLENGTH variable is 5
---------------------------------
Match of m.*y found at 16 in groad is a forum mainly for linux.
RSTART variable is 16
RLENGTH variable is 8
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |