bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Inconsistent -F


From: Michael Witten
Subject: Inconsistent -F
Date: Fri, 16 Jul 2010 11:45:49 -0500

Consider these examples:

#0:

 $ echo '[ a [' | gawk '/[/ {print $2}'
 gawk: /[/ {print $2}
 gawk:  ^ unterminated regexp
 gawk: fatal: Unmatched [ or [^: /[/ {print $2}/

#1:

 $ # Escape the offending [
 $ echo '[ a [' | gawk '/\[/ {print $2}'
 a

#2:

 $ # Introduce -F'['
 $ # Why is this NOT offensive?
 $ echo '[ a [' | gawk -F'[' '/\[/ {print $2}'
  a

#3:

 $ # Try escaping the [ in -F'['
 $ # Why IS this offensive?
 $ echo '[ a [' | gawk -F'\[' '/\[/ {print $2}'
 gawk: warning: escape sequence `\[' treated as plain `['
  a

Example #0 complains about the special ERE character '[' being used
incorrectly; the solution is to escape that special character, which
is done in Example #1; however, after skimming the POSIX manual for
awk, it seems that '\[' is considered undefined, so is the ability to
escape special characters in regular expressions a gawk extension?

Nevertheless, Example #2 uses an unescaped '[' in the ERE for the '-F'
option, but acts as though it is espaced (by matching the string "[");
this is inconsistent with the behavior in Example #0. Worse, Example
#3 shows that gawk doesn't even like the escaped version.

In #awk, geirha pointed out that gawk seems to evaluate the escape
sequences twice when processing the argument to the option '-F':

#4:

 $ echo '[ a [' | gawk -F'\\[' '/\[/ {print $2}'
  a

What is the reason for this? Why aren't '-F' regular expressions and
pattern regular expressions treated the same way? Is this a bug that
remains for backwards compatibility, or am I missing some subtle
point?

Sincerely,
Michael Witten



reply via email to

[Prev in Thread] Current Thread [Next in Thread]