AwkGuide
** Work in Progress ** {{{ import from Mark Hobley's wiki }}} <toc> ---- == Overview * [[Overview]] . . . * [[redirection]] * [[RS|record separator]] * [[regular expression]]s * [[regular expression operator]]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 . . . close(s); is ok Except when n=-1 then message #: regular expression metacharacters: \ . ^ $ [ ] | + . . .
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 . . . ~ /pattern/**. That is, when awk sees a single regular expression used as an expression, it implicitly . . . on the fact that GNU awk supports assigning a regular expression to RS (the standard only allows . . . reads a series of "records", separated by the regular expression matching /FOO[0-9]*\n/ (that is, . . . here is to perform a string comparison against a regular expression: {{{ awk -F '[.]' 'function ok(n) . . .
31K - last updated 2009-03-24 16:54 UTC by waldner
Backref2
The usual (and correct) answer for backreferences in awk (for example, the answer you can get on #awk . . . If you need to //**match**// a pattern using a regular expression with backreferences, like eg you . . .
2K - last updated 2009-03-26 20:24 UTC by waldner
Backreferences
The usual (and correct) answer for backreferences in awk (for example, the answer you can get on #awk . . . If you need to //**match**// a pattern using a regular expression with backreferences, like eg you . . .
3K - last updated 2010-12-30 06:53 UTC by ppp089210039107.dsl.hol.gr
backslash
In [[awk]], the backslash symbol can be used: * as a line [[continuation]] character * for suppression . . . * for [[suppression of interpolation within a regular expression]] * insert [[literal character]]s . . .
1K - last updated 2011-05-09 22:34 UTC by markhobley
BackslashInRegexp
Because {{{"\\$"}}} is a string and {{{/\\$/}}} is not; in strings, some of the escape characters get . . . double-quote within the string). {{{ /\\$/ => regular expression: literal backslash at end-of-expression . . . "\\$" => string: \$ => regular expression: literal dollar sign }}} To get . . .
2K - last updated 2008-11-26 12:27 UTC by pgas
BeforeAfterMatch
Problem: print the Nth record before or after a certain regular expression matches or, alternativley, . . . record except the Nth before or after a certain regular expression matches. In the same way, print . . . above can have problems if the pattern contains regular expression metacharacters, so in that case . . .
3K - last updated 2009-02-28 20:38 UTC by waldner
continuation
Line continuation enables long lines of code to split across several lines for the purpose of making . . . middle of a [[keyword]], [[literal string]] or [[regular expression]]: {{{ # Do not split a regular . . .
1K - last updated 2011-05-09 22:48 UTC by markhobley
CookBook
<toc> ---- Just started, the aim of this page is to collect small pieces of code that illustrate . . . last matching substring on a line for a given regular expression <include "LastMatchOnLine"> . . .
1K - last updated 2009-04-14 09:03 UTC by 216.162.199.202
dollar
== Prefixing field numbers == The dollar symbol can be used to prefix [[field]] numbers: == Regular expression . . . anchoring == The dollar symbol is used as a regular expression [[anchor]] to match the end of a . . .
1K - last updated 2010-11-28 10:46 UTC by markhobley
dot
== The dot symbol == === The dot symbol as a regular expression operator === The [[dot]] symbol can be . . . used as a [[regular expression operator]] to match any single character. . . .
1K - last updated 2010-11-11 23:41 UTC by markhobley
FIXES
[[FIXES]] revised: . . . as well as on the commandline.\\ Added \x to regular expressions (already in strings).\\ awk -f . . .
6K - last updated 2014-01-15 23:17 UTC by g0ph3r
Frequently Asked Questions
Some entries of this page have been copied from the [[comp.lang.awk_FAQ]]([[http://awk.freeshell.org/comp.lang.awk_FAQ#toc29|Credits]]) . . . answer]] ---- == How do I use a variable as a regular expression? <include "VariablesInRegex"> . . .
3K - last updated 2015-09-08 08:46 UTC by pgas
FS
= Field Separator = The [[special variable]] FS is a field separator that is used to determine how [[awk]] . . . an empty field, then it is possible to use a regular expression containing a space in a box enclosures . . . field separator can be a single character or a regular expression: {{{ # Change the field separator . . . to a colon FS = ":" }}} === _Using a regular expression as a field separator_ In the following . . . example, we use a regular expression '''l.[^l]''', which represents a . . .
5K - last updated 2013-02-19 21:45 UTC by markhobley
gawkism
Gawkisms are non portable syntax components that do not work with some awk implementations. The use of . . . operator * [[PROCINFO]] * [[RS]] can be a [[regular expression]] * [[rshift]] (bitwise function) . . .
2K - last updated 2011-05-19 22:29 UTC by markhobley
operator
The [[awk]] programming language provides a series of *operators* that allow [[value]]s and [[variable]]s . . . operators * [[comparative operator]]s == regular expression operators * [[regular expression . . .
3K - last updated 2011-05-24 22:19 UTC by markhobley
Overview of regular expressions
== What is a regular expression? == A regular expression is a method of representing a string matching . . . pattern. Regular expressions enable strings that match a particular . . . that manipulate textual data. For example, a regular expression can be used to replace the word . . . throughout an entire piece of text, or a regular expression could be used to locate particular . . . the words "Lion" and "Lamb" on the same line. Regular expressions are extremely powerful. Regular . . .
2K - last updated 2011-05-17 20:32 UTC by markhobley
pattern
In [[awk]], patterns are used to select lines of input for processing. The pattern within each [[rule]] . . . the pattern was omitted from the [[rule]]. === Regular Expression Patterns === A pattern may contain . . . [[regular expression]]s for matching text within a string. . . . symbol is used as an [[enclosure]] for [[regular expression]]s used in the pattern. In the following . . . line) will occur for each line that match the [[regular expression]] foobar. {{{ /foobar/ {print $0} . . .
2K - last updated 2011-05-19 18:18 UTC by markhobley
RangeOfFields
Printing a range of fields - all fields but the first, for examples, or fields 3 through 8 - is a surprisingly . . . uses the default FS. Finally, if FS is a full regular expression, then the problem is not trivial . . . when the field separator is a full regular expression: {{{ bash awk ' { nf = split($0, . . . field separator is {{{" "}}} (a blank); for a regular expression field separator {{{fld[0]}}} and . . .
10K - last updated 2015-09-08 09:52 UTC by pgas
regular expression
<toc> ---- * [[Overview of regular expressions]] * [[regular expression operator]]s * [[Simple . . . Regular Expression]]s * [[Basic Regular Expression]]s . . . * [[Extended Regular Expression]]s * [[Perl Compatible Regular Expression]]s . . . * [[nested regular expression]]s ---- . . .
1K - last updated 2008-12-30 12:12 UTC by Mark Hobley
regular expression operator
The [[awk]] programming language provides a set of *regular expression operators* that have special meanings . . . within [[regular expression]]s. == _Regular Expression Binding . . . Operators_ The *regular expression binding operator* applies the the . . . right hand operand as a regular expression to the left hand operand and return . . . was found. * ~ Returns a value of true if the regular expression matches the left hand operand. {{{ . . .
2K - last updated 2013-02-19 14:06 UTC by markhobley
SedFAQ
<toc> ---- == I have a line like "abdcgfjeuPATTERNfjfhghj", I want to get the PATTERN part, why . . . result! (I want fooZZar, but I get ZZfoobar) Regular expressions that match 0 or more occurrences . . . expression is matching. == But I've read that regular expressions are greedy! They surely are greedy, . . . Interesting bits are recognized using patterns (regular expressions) only. *ML documents, on the other . . . very difficult (to say the least) to write a regular expression that can take care of all the above . . .
34K - last updated 2010-02-14 17:56 UTC by waldner
slash
== Division Operator == The slash symbol is used as the division operator to produce the [[result]]s . . . of two [[operand]]s: $answer = 18 / 3; # 6 == Regular Expression Enclosure == The slash symbol is . . . used as an [[enclosure]] that marks a [[regular expression]] as a [[pattern]]: {{{ # foobar . . . is a regular expression used as a pattern /foobar/ { print . . .
1K - last updated 2011-05-11 15:00 UTC by markhobley
statement
The [[awk]] extraction and reporting language is not [[imperative]]. However, [[action]]s within the . . . including the middle of a [[string]] or [[regular expression]]: {{{ # Here the regular expression . . .
2K - last updated 2011-05-21 16:43 UTC by markhobley
suppression of interpolation within a regular expression
The [[backslash]] symbol is be used to prevent [[interpolation]] of [[metacharacter]]s within the program. . . .
1K - last updated 2010-02-01 20:54 UTC by MarkHobley
symbol
| *Symbol* | *Name* | *Purpose* | !! | [[pling]] | logical NOT | " | [[doublequote]] | | # | [[hash]] . . . | $ | [[dollar]] | field reference operator and regular expression anchor | % | [[percent]] | | & . . . | * | [[asterisk]] | multiplication operator and regular expression operator | + | [[plus]] | optional . . . positive number prefix, addition operator and regular expression operator | , | [[comma]] | separates . . . | negative number prefix, subtraction operator, regular expression range operator | . | [[dot]] | decimal . . .
2K - last updated 2013-02-19 14:26 UTC by markhobley
text.2.wiki.awk
#: C:\#\awk\lib\text.2.wiki.awk\\ . . . i..n integers; w..z reals\\ {{{ #: regular expression metacharacters: \ ^ $ . [ ] | ( . . .
11K - last updated 2012-09-24 14:55 UTC by g0ph3r
text 2 wiki.awk
{{{ #: C:\#\lib\awk\utl\text_2_wiki.awk #: 2012-09-15 23:40:11 #:rod.t_2012 #: This file is http://awk.freeshell.org/text_2_wiki.awk . . . s..v strings; i..n integers; w..z reals #: regular expression metacharacters: \ ^ $ . [ ] | ( . . .
2K - last updated 2012-09-16 09:12 UTC by g0ph3r
tilde
== Substring containment operator == The tilde [[symbol]] can be used as a containment operator providing . . . a [[pattern]] match if a string matches a [[regular expression]]: === Non containment operator . . .
1K - last updated 2011-05-19 19:04 UTC by markhobley
tracert.awk
{{{ awk #:: C:\_\_u\tracert.awk #: 2014-07-06 19:47:02 #:: rod.t_2014 #:: extract basename for tracert . . . data lines: -v s=\136##:[\040\t]* sub(s,n)==1 #: regular expression metachars: \ / ^ $ . [ ] | ( ) * . . .
4K - last updated 2014-07-07 06:15 UTC by 212.205.56.222
VariablesInRegex
The patterns between slashes like /pattern/ are called **ERE constants**, or **regular expressions literals**. . . . imply, they can only contain fixed, constant regular expressions. If you have a variable //var// . . . the literal string "var", not against the regular expression. You can still use strings in places . . . where regular expressions are expected, like this: {{{ awk . . . Also note that when you're using a string as a regular expression you must explicitly match it against . . .
2K - last updated 2010-11-26 08:49 UTC by 195.97.26.99
WartAndWishList
Awk is a wonderful language! That said, there are a few annoying bits... == The Good * well-documented . . . \n And a newline}}}); if a string is used in a regular expression context, a further level of escaping . . . by strings. Arrays cannot contain other arrays, regular expressions, functions... (but you can use . . .
7K - last updated 2009-04-13 18:39 UTC by goedel
33 pages found.