split(string, array [, fieldsep [, seps ] ])
awk ' \
{ if(length(dataField) > 0) print dataField } \
\
' file.log
gsub(regexp, replacement [, target])
Like gsub, gensub allows regex-based search and replace. Some of its notable differences are :
- the replacement string can refer to subparts of the matched string using callbacks
- gensub returns the modified string as the result of the function. The original target string is not changed. So you'll have to explicitly store the result in a variable and print it.
gensub(regexp, "replacement", how [, target])
- regexp : explicit
- replacement : callbacks are
\1
to \9
. Since replacement is a quoted string, the \
characters need to be escaped, and callbacks will appear as \\n
- how :
- if it starts with
g
or G
(i.e. "global") : replace all matches
- otherwise, consider it as a number indicating which match of regexp to replace. If < 1, assume
1
.
- target : the field to search+replace into. If missing, assume
$0
.
Here's a very basic example (not-so-perfect but you'll get the idea ) :
echo 'abc' | awk '{
switch ($0) {
case /[[:lower:]]+/:
print "lowercase"
break
case /[[:upper:]]+/:
print "uppercase"
break
}
}'
As a one-liner that can be pasted into the shell :
echo 'abc' | awk '{ switch ($0) { case /[[:lower:]]+/: print "lowercase"; break; case /[[:upper:]]+/: print "uppercase"; break; } }'
checkPageExists() {
local page=$1
curl -sI "$page" | awk '/^HTTP\/1.1/ {
if ($2=="200")
exit 0
else
exit 1
}'
}
main() {
for page in $pageList; do
checkPageExists "$page" || continue
done
}