Gawk manual sub






















(This must be typed as "\\"; see GAWK: Effective AWK Programming for a fuller discussion of the rules for ampersands and backslashes in the replacement text of sub(), gsub(), and gensub().) index(s, t) Return the index of the string t in the string s, or zero if t is not present. (This implies that character indices start at one.). The sub function returns the number of substitutions made (either one or zero). If the special character `' appears in replacement, it stands for the precise substring that was matched by regexp. (If the regexp can match more than one string, then this precise substring may vary.) For example: awk '{ sub(/candidate/, " and his wife"); print }'. $ gawk ' BEGIN { a = "abc def" b = gensub(/.+) .+)/, "\\2 \\1", "g", a) print b }' -| def abc As with sub, you must type two backslashes in order to get one into the string. In the replacement text, the sequence ` \0 ' represents the entire matched text, as does the character ` .


$ gawk ' BEGIN { a = "abc def" b = gensub(/.+) .+)/, "\\2 \\1", "g", a) print b }' -| def abc As with sub, you must type two backslashes in order to get one into the string. In the replacement text, the sequence \0 represents the entire matched text, as does the character . GAWK: Effective AWK Programming A User’s Guide for GNU Awk Edition October, Arnold D. Robbins. (This must be typed as "\\"; see GAWK: Effective AWK Programming for a fuller discussion of the rules for ampersands and backslashes in the replacement text of sub(), gsub(), and gensub().) index(s, t) Return the index of the string t in the string s, or zero if t is not present. (This implies that character indices start at one.).


This is Edition 4 of GAWK: Effective AWK Programming: A User's Guide for GNU Gory Details: More than you want to know about ' \ ' and ' ' with sub(). The first argument to sub and gsub functions can be a string as well, awk will info See gawk manual: Gory details for more information than you'd want. Note: As mentioned above, the third argument to sub must be a variable, field or array reference. Some versions of awk allow the third argument to be an.

0コメント

  • 1000 / 1000