AA-awk-history
http://awk.freeshell.org/AA-awk-history\\ a concise history of awk and some of its forks\\ {{{ common . . . keywords: do delete function return\\ [3] current maintainer - the dr. k of awk\\ . . .
2K - last updated 2013-10-26 02:28 UTC by g0ph3r
Adler32Checksum
As documented in the [[http://en.wikipedia.org/wiki/Adler-32 | Adler-32 Wikipedia article]]. {{{ awk . . . the checksum of a substring; hacker beware! } } return a + (2^16 * b) # gawk supports bitwise operations . . . Also recall # that Adler32 is supposed to return its results in network # order; we punt and . . . simply return an integer, and we leave the # dirty conversion . . .
4K - last updated 2008-12-31 12:05 UTC by pgas
ArrayLength
Posix does not define a way to get the length of an array, while you could use a loop to count the elements . . . "the length of a is %d\n",n #remember that split returns a value n=split("foo bar",a) printf "the length . . .
2K - last updated 2009-02-09 09:45 UTC by arnold.robbins
awk nawk oawk
in 1977 there was awk.\\ this page attempts to explain the history of awk.\\ the 1978 7th Edition awk(1) . . . RLENGTH SUBSEP\\ keywords: do delete function return\\ the latest One True awk:\\ http://www.cs.princeton.edu/~bwk/btl.mirror/index.html\\ . . . #: can not access array or function names return(1); } }}} . . .
2K - last updated 2012-03-18 23:21 UTC by g0pher
AwkDc
This is an awk implementation of the [http://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html|dc] . . . { #print "op: " op >> "/dev/stderr" return } function putstring(stk, str) { _dc_put(stk, . . . = num } function _dc_pop(stk) { showop("pop") return stk[stk[SP]--] } # }}} ----- # TYPE VERIFICATION . . . FUNCTIONS {{{ ----- function _dc_isnum(val) { return (val ~ /^-?[0-9]+(\.[0-9]+)?$/) } function _dc_isint(val) . . . { return (val ~ /^-?[0-9]+$/) } function _dc_isstr(val) . . .
12K - last updated 2008-07-17 14:47 UTC by gnomon
AwkGuide
** Work in Progress ** {{{ import from Mark Hobley's wiki }}} <toc> ---- == Overview * [[Overview]] . . . expression operator]]s * [[repeat]] loops * [[return]] * [[RS]] * [[rule]]s * [[search pattern]]s . . .
4K - last updated 2011-08-14 15:57 UTC by markhobley
AwkOnWindowsHowto
AwkOnWindowsHowto\\ rough cut - needs edit {{{ 3) awk command line switches/usage from a win32 cmd.exe . . . operators are valid instead of ^ #: system() returns errorcode/256 eg system("%awk% BEGIN{exit(256)}) . . .
3K - last updated 2010-10-24 07:44 UTC by g0pher
AwkTips
<toc> ---- == Be idiomatic! In this paragraph, we give some hints on how to write more idiomatic . . . expression, it implicitly applies it to $0, and returns success if there is a match. Then we have: . . . valid program: {{{ awk -F '[.]' 'function ok(n){return (n>=0 && n<=255)} {exit (NF==4 . . . expression: {{{ awk -F '[.]' 'function ok(n) { return (n ~ /^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$/) . . . the following function: {{{ function ok(n) { return (n !~ /[^0-9]/ && n>=0 && . . .
31K - last updated 2009-03-24 16:54 UTC by waldner
Backreferences
The usual (and correct) answer for backreferences in awk (for example, the answer you can get on #awk . . . }}} Note that gensub(), unlike sub() and gsub(), returns the modified string without touching the original. . . .
3K - last updated 2010-12-30 06:53 UTC by ppp089210039107.dsl.hol.gr
calling section
A '''calling section''' is a section or [[block]] of code that makes a call to a subroutine or [[function]]. . . . be a call instruction or function name. === Return point === The return point is the instruction . . . after the [[subroutine]] or [[function]] has returned. == Evaluation of return values == The code . . . at the return point within a program may evaluate the [[return . . .
1K - last updated 2011-05-06 21:57 UTC by markhobley
case conversion
The [[awk]] extraction and reporting language provides the toupper and tolower functions for converting . . . === Description === The tolower function returns a lowercase version of the STRING argument. . . . converts all letters to lowercase in the returned string. Only the returned string is converted, . . . === Description === The toupper function returns a lowercase version of the STRING argument. . . . converts all letters to uppercase in the returned string. Only the returned string is converted, . . .
2K - last updated 2011-06-25 05:10 UTC by pgas
CAWKLib
=CAWKLib CAWKlib is a library of functions for for awk intended to be used with preprocessors/wrappers . . . as it is today arrays.awk: *ary_length() -- return the length of an array (meaning the number of . . . elements/values/indices) *ary_width() -- return the width of an array (meaning the number of . . . in a multi-dimensional array) *ary_choice() -- return random index from an array strings.awk: *str_capitalize() . . . -- returns a string with the first character capitalized . . .
5K - last updated 2015-01-29 10:14 UTC by 108-243-116-77.lightspeed.cicril.sbcglobal.net
ConvertHexToFloatingPoint
This code uses [[gawkism|gawk specific features]], such as the [[http://www.gnu.org/manual/gawk/html_node/Strtonum-Function.html][strtonum]] . . . * 2^(exponent-bias) if(sign) fval=fval*-1 return fval } BEGIN { } { print HexToFP($4, $3, $2, . . . ",(*(p+i)&0xFF)); printf("%.3f\n",f[j]); } return 0; } }}} ===== Here's another form of the same . . . of the original number if(sign != 0) fval *= -1 return fval } BEGIN { x = f_ieee754(0x41f24000) printf("x . . .
3K - last updated 2010-06-23 19:49 UTC by john b
division
== Quotient Division == The [[slash]] symbol can be used as the division [[operator]] to produce the . . . a division by zero is encountered. Instead mawk returns an inf string without producing a warning or . . .
2K - last updated 2011-03-20 07:07 UTC by markhobley
EmptyArray
You can test if an array is empty using this function: {{{ awk function empty(a, i) { for(i in a) return . . . 0; return 1} }}} This function comes from comp.lang.awk . . .
1K - last updated 2009-03-12 08:11 UTC by pgas
escape sequence
Some characters cannot be included in [[literal string]]s, because they are [[nonprintable]] or [[control . . . | \f | formfeed | \n | newline | \r | carriage return | \t | tab | \v | vertical tab == Literal characters . . .
3K - last updated 2008-12-30 13:07 UTC by Mark Hobley
exponent
==Warning! The use of [[gawkism]]s will prevent the script from running correctly on systems that use . . . acts as a dyadic exponent [[operator]]. It returns the [[value]] given as a left [[operand]] to . . .
2K - last updated 2012-03-20 07:33 UTC by g0pher
FileExistence
The most portable way to test for the existence of a file is to simply try and read from the file. {{{ . . . empty) and can be read ret = 1; close(file); } return ret; } }}} [ I've read reports that earlier . . . of mawk would write to stderr as well as getline returning <0 -- is this still true? ] On Unix, you . . .
1K - last updated 2008-11-18 13:26 UTC by pgas
FileExistenceJapanese
The most portable way to test for the existence of a file is to simply try and read from the file. {{{ . . . empty) and can be read ret = 1; close(file); } return ret; } }}} [ I've read reports that earlier . . . of mawk would write to stderr as well as getline returning <0 -- is this still true? ] On Unix, you . . .
1K - last updated 2008-11-24 08:07 UTC by pgas
FindAllIndices
Sometimes it is useful to find the index of every occurrence of a given character in a string. Let's . . . i++) if (substr(str, i, 1) == chr) arr[++j] = i return j } }}} The function returns the number of instances . . .
2K - last updated 2011-07-05 10:53 UTC by pgas
FindAllMatches
This bit of code will match all non-overlapping instances of a given pattern in a string and will store . . . the matches in the given array. It returns the number of patterns found. This duplicates . . . RSTART+RLENGTH) } RSTART = a; RLENGTH = b return j } }}} TODO: correctly handle 0-length matches. . . . REs (eg, if RE is "^foo" and str is "foofoo", return only one "foo") - HARD . . .
2K - last updated 2009-03-24 09:46 UTC by waldner
FIXES
[[FIXES]] revised: . . . close() is now a function. it returns whatever the library fclose returns,\\ and . . . flushes all files and pipes.\\ length(arrayname) returns number of elements (Jan 1, 2002)\\ subtle change . . . for subsequent splits.\\ changed srand() to return the previous seed (which is 1\\ on . . . octal instead ie -v alert=\007\\ system() returns errorcode / 256 (in windows)\\ cmd **{{{|}}}** getline; n . . .
6K - last updated 2014-01-15 23:17 UTC by g0ph3r
GeneralizedTextReplacement
Some times people need to recode in awk something they were previously doing with sed or another tool. . . . after mtch[n]) newstr=newstr substr(orgstr,last) return newstr } # main body of the program; here we . . .
6K - last updated 2009-03-26 20:38 UTC by waldner
GeoLocation
{{{ awk #!/bin/gawk -f function getcoord(string, a) { split(string, a, ":") gsub(/\"/, "", a[2]) return . . . = 0 while (socket |& getline) { if (in_body) return $0 if (/^\r$/) in_body = 1 } } BEGIN { data . . .
1K - last updated 2011-11-14 16:35 UTC by pgas
Glossary
[[Glossary| Glossary]]\\ see also [[AwkOnWindows| AwkOnWindows]] and [[FIXES| FIXES]] and [[AwkOnWindowsHowto| . . . characters are blank, tab, newline, carriage return, vertical tab, and formfeed.' me: 'yes, i am . . .
2K - last updated 2010-10-24 08:14 UTC by g0pher
index
== Usage == === index [ STRING, SUBSTRING ] === The index [[function]] is used to locate the first occurrence . . . cannot be found, then a value of [[zero]] is returned: BEGIN { print index("Staffordshire","ford") . . .
1K - last updated 2011-06-09 20:36 UTC by markhobley
LastMatchOnLine
The function 'match' sets RSTART to the index of each match and RLENGTH to its length, and returns 0 . . . RLENGTH) line = substr(line, RSTART+RLENGTH) } return result } }}} . . .
1K - last updated 2009-04-14 22:07 UTC by 216.162.199.202
length
== Usage == === length ([ STRING ]) === The **length** function returns the number of characters within . . .
1K - last updated 2011-06-25 05:11 UTC by pgas
LevenshteinEditDistance
The [http://en.wikipedia.org/wiki/Levenshtein_distance|Levenshtein edit distance] calculation is useful . . . tog, arr, i, j, a, b, c) { if (str1 == str2) { return 0 } else if (str1 == "" || str2 == "") { return . . . (substr(str1, a, 1) == substr(str2, a, 1)) a++ return levdist(substr(str1, a), substr(str2, a)) } . . . l1-b, 1) == substr(str2, l2-b, 1)) b++ return levdist(substr(str1, 1, l1-b), substr(str2, . . . a : ((b<=a)&&(b<=c)) ? b : c) } } return arr[tog, j-1] } }}} ---- === Ancillary Code . . .
6K - last updated 2010-04-16 10:19 UTC by pgas
libmawk
libmawk is a fork of [[mawk]], designed for embedding in C programs. Compare and contrast with [[awka]]. . . . ** dynamic variable value fetch (valueof() returns the value of a variable by name) ** include . . .
2K - last updated 2012-01-16 09:07 UTC by lewellyn
literal characters
== Special characters cannot be directly included in a literal string == Special characters, such as . . . | \f | form feed | \n | newline | \r | carriage return | \t | tab | \v | vertical tab | \\ | backslash . . .
2K - last updated 2010-11-28 19:14 UTC by markhobley
logical operator
In [[awk]], *logical operators* are used to perform [[boolean]] operations, and a return a value of [true] . . . | [[and]] | [[doubleampersand &&]] | Returns [true] if both [[operand]]s are [[true]], otherwise . . . returns [[false]] | [[or]] | [[doublepipe]] | Returns . . . or both [[operand]]s are [[true]], otherwise returns [[false]] | [[not]] | [[pling !]] | Returns . . . [[false] if [[operand]] is [[true]], otherwise returns [[true]] Traditionally, [[awk]] does not provide . . .
3K - last updated 2009-01-02 11:13 UTC by pgas
LshalOutputParser
=== Problem Specification 10:50 <Thanatermesis> i want to obtain the model of the disk, for example, . . . { sub(/^ +/, "", str) sub(/ +$/, "", str) return str } function startBlock() { split("", PROPERTIES) . . . PROPERTIES["storage.model"] } return } ########################################## . . .
3K - last updated 2008-06-27 16:22 UTC by gnomon
modulus
The [[dyadic]] modulus [[operator]], represented by a [[percent]] sign is used to return the remainder . . .
1K - last updated 2011-06-07 00:41 UTC by markhobley
multiplication
== Multiplication Operator == The multiplication operator represented by the star symbol, is used as . . . a dyadic operator used to return the calculated product of two operands multiplied . . .
1K - last updated 2011-04-17 06:32 UTC by markhobley
nudge operator
The *nudge operators* can be used to [[increment]] or [[decrement]] the value of their [[operand]]s, . . . will attempt to add or subtract one to obtain a return value: {{{ number = 5.4 result = ++number # . . . an expression, so the nudge operators will return appropriate results: {{{ number = "1" result . . . numeric expression, and the nudge operators will return a value relative to that: {{{ string = "abc" . . .
3K - last updated 2011-03-20 13:18 UTC by markhobley
operator
The [[awk]] programming language provides a series of *operators* that allow [[value]]s and [[variable]]s . . . are used to perform [[boolean]] operations, returning either [[true]] or [[false]]. == nudge operators . . .
3K - last updated 2011-05-24 22:19 UTC by markhobley
PrintASingleQuote
This question gets asked often enough that it deserves its own answer. This common question doesn't actually . . . out the string "it said 'Hello, World!' and then returned 0", one can run the following program: {{{ . . . BEGIN { print "it said 'Hello, World!' and then returned 0" exit 0 } }}} However, when one attempts . . . 'BEGIN{print "it said 'Hello, World!' and then returned 0";exit 0}' }}} ...the shell complains, because . . . "it said \x27Hello, World!\x27 and then returned 0";exit 0}' }}} ...but this consistency is . . .
5K - last updated 2015-07-05 09:45 UTC by pitman
PrintASingleQuoteJapanese
This page is the translated page of PrintASingleQuote written in Japanese. この問題は何度も質問される内容なので、議論するのに値する問題です。 . . . BEGIN { print "it said 'Hello, World!' and then returned 0" exit 0 } }}} しかしながら、同じことをコマンドラインで実行すると・・・ . . . 'BEGIN{print "it said 'Hello, World!' and then returned 0";exit 0}' }}} ・・・shell は 2 つのシングルクォートの間に挿入されているコマンドの文字として . . . "it said \x27Hello, World!\x27 and then returned 0";exit 0}' }}} ・・・でも、この一貫性は偽りなのです。 gawk, . . .
3K - last updated 2008-10-15 14:22 UTC by hi saito
qse
Not a standalone awk, but an interesting library embedding an awk interpreter, from [[https://groups.google.com/group/comp.lang.awk/browse_thread/thread/b02c0d75e49eab75/54fc2c6316d657bc?lnk=gst&q=c%2B%2B+embed#54fc2c6316d657bc| . . . with or without parameters and getting its return value. * customizing I/O handlers for file, . . . (rtx, retv); /* destroy the return value */ ret = 0; oops: if (rtx) qse_awk_rtx_close . . . qse_awk_close (awk); /* close the interpreter */ return ret; } }}} Things can get simpler when you use . . . awk.getErrorMessage() << std::endl; \ return -1; \ } while (0) int main (int argc, char* . . .
4K - last updated 2011-10-27 06:25 UTC by pgas
RangeOfFields
Printing a range of fields - all fields but the first, for examples, or fields 3 through 8 - is a surprisingly . . . without the separator to the output string and returns said string. {{{ awk # usage: extract_range(string, . . . FS, with the # original field separators intact. returns the extracted fields. function extract_range(str, . . . FS left, therefore the range is empty } else { return ""; } } # add fields start through stop - 1 . . . no FS left, just append the rest of the line and return } else { return out str; } } # append the last . . .
10K - last updated 2015-09-08 09:52 UTC by pgas
Recursively Include C headers
=== Problem Specification i want to generate one big .hpp file out of multiple .hpp files and want to . . . complete_path(file, p) { if (file ~ /^[\/.]/) return file for (i = 1; i <= iplen; ++i) { p = ip[i] . . . -f \"%s\"", p)) == 0) return p } printf("error:%s: file not found in include_path\n", . . .
1K - last updated 2011-12-11 05:33 UTC by pgas
regular expression operator
The [[awk]] programming language provides a set of *regular expression operators* that have special meanings . . . regular expression to the left hand operand and return a truth value depending on whether or not a . . . match was found. * ~ Returns a value of true if the regular expression matches . . .
2K - last updated 2013-02-19 14:06 UTC by markhobley
RepeatAString
Sometimes it is useful to have something like Perl's 'x' operator, which repeats a string N times. This . . . 2 == 1) result = rep(str, (num - remain) / 2) } return result result (remain ? str :"") } }}} The function . . .
1K - last updated 2009-03-01 19:15 UTC by h-67-101-152-180.nycmny83.dynamic.covad.net
return
The [[builtin]] '''return''' [[command]], can be used to exit from a [[function]] within the [[awk]] . . . script, returning control to the [[calling section]]. The return . . . [[command]] takes the form of: return foo Where foo is an [[expression]] that evaluates . . . to a [[return value]] that is to be made available to the . . . [[calling section]]. === Using the return value command to set an errorlevel === By convention, . . .
2K - last updated 2011-05-03 17:29 UTC by markhobley
reverse
The [[awk]] extraction and reporting language does not provide a [[builtin]] function for reversing strings. . . . 0 ; l--) { c = substr(s, l, 1) revs = revs c } return revs } # Call the reverse function to reverse . . .
1K - last updated 2011-06-25 05:11 UTC by pgas
Shellquote
This function ensures that strings you use as arguments to the **system()** function (or **"cmd"{{{|}}}getline** . . . shellquote(str) { gsub(/'/, "'\\''", str) return sprintf("'%s'", str) } }}} . . .
1K - last updated 2009-03-01 00:35 UTC by h-67-101-152-180.nycmny83.dynamic.covad.net
SimpleCalc
Simple 4 operations calculator ... {{{ awk # usage: print calc("5 * (1 + 2) * 5 + 7") # reads and update . . . s[0] # return the first token function next_token(s, t) { . . . RSTART, RLENGTH) s[0] = substr(s[0], RLENGTH+1) return t } else { return "" } } # read input and performs . . . algorithm # result is in postfixed # return the length of the postfixed array function s_y( . . . -= 1 } if (head == 0) { print "Syntax Error" return 0 } else { head -= 1 } } } while ((head > . . .
2K - last updated 2015-09-10 06:14 UTC by pgas
SizeOfSplit
How many elements were created by split()? When I do a split on a field, e.g., {{{ awk split($1,x,"string") . . . (n in x)' test)? split() is a function; use its return value: {{{ awk n = split($1, x, "string") }}} . . .
1K - last updated 2008-11-18 12:35 UTC by pgas
text.2.wiki.awk
#: C:\#\awk\lib\text.2.wiki.awk\\ . . . return(close(c));\\ }\\ \\ function . . . return((ss "`"));\\ }\\ ## \\\\\ . . .
11K - last updated 2012-09-24 14:55 UTC by g0ph3r
tracert.awk
{{{ awk #:: C:\_\_u\tracert.awk #: 2014-07-06 19:47:02 #:: rod.t_2014 #:: extract basename for tracert . . . "") always true if(_debug < 2) break; } return(s); } function _testf( cmd, s, t) { ##: htpp://.www.newegg.com./pr/pr.aspx?item=n82e . . . for(i in ENVIRON) if(tolower(i) == s) \ return(ENVIRON[i]); return(""); } function _dt( s) . . . "", s); gsub(" ", "0", s); gsub(/_/, " ", s); return(s); } ## _____ #: paradigm: A,B.. arrays; s..v . . .
4K - last updated 2014-07-07 06:15 UTC by 212.205.56.222
WartAndWishList
Awk is a wonderful language! That said, there are a few annoying bits... == The Good * well-documented . . . that operates on strings. * There is no way to return an array from a function. It is possible to . . .
7K - last updated 2009-04-13 18:39 UTC by goedel
52 pages found.