NetBSD Problem Report #650

From gnats  Tue Dec 20 08:20:04 1994
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id IAA03131 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Tue, 20 Dec 1994 08:20:02 -0800
Message-Id: <199412201622.JAA00164@baskerville.CS.Arizona.EDU>
Date: Tue, 20 Dec 1994 09:22:15 -0700
From: ram@cs.arizona.edu
Reply-To: ram@cs.arizona.edu
To: gnats-bugs@netbsd.org
Subject: possible bug with regular expressions in awk
X-Send-Pr-Version: 3.2

>Number:         650
>Category:       bin
>Synopsis:       backslash does not escape *
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 20 08:35:03 +0000 1994
>Closed-Date:    Sun Jan 15 10:22:13 +0000 1995
>Last-Modified:  
>Originator:     
>Release:        
>Organization:
"	"
>Environment:

System: netbsd 1.0 i386


>Description:
	The sub command, when used in awk does not properly escape the
	meaning of *.
>How-To-Repeat:


BTW -- I "ported" send-pr to my solaris machine to send the email report. 
Sorry if I left something out.


	file bar has:
janis:ram {58} cat bar
MOVIE RATINGS REPORT

New  Distribution  Votes  Rank  Title
      .0.03020..      11   5.5  $
      .121100...      11   4.0  $1,000,000 Duck
      0011211000     142   5.0  'burbs, The
      0000122100     418   6.4  'Crocodile' Dundee
      .2.224....       5   4.6  After School
      ..2.24....       7   4.9  After the Fall of New York
      ...0522...      14   5.6  After the Fox
 *    ...242.2..       5   5.6  After the Rehearsal
janis:ram {59} 


Use this awk program to see the problem:

#!/usr/bin/awk -f

BEGIN {
  in_report=0
}

/MOVIE RATINGS REPORT/ {
  in_report=1
}

in_report==1 && /[0-9\.][0-9\.][0-9\.][0-9\.][0-9\.][0-9\.][0-9\.][0-9\.][0-9\.][0-9\.]/ {
  new_line = $0;
  sub( "^ \* ", " X ", new_line);
  print new_line
}


Running the following line "cat bar | filter_ratings" gives 
 X .0.03020..      11   5.5  $
 X .121100...      11   4.0  $1,000,000 Duck
 X 0011211000     142   5.0  'burbs, The
 X 0000122100     418   6.4  'Crocodile' Dundee
 X .2.224....       5   4.6  After School
 X ..2.24....       7   4.9  After the Fall of New York
 X ...0522...      14   5.6  After the Fox
 X *    ...242.2..       5   5.6  After the Rehearsal

Apparently the sub command is matching all leading white space. When the
backslash should force the regexp to match a space asterisk space.

>Fix:
	I have no idea.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mycroft 
State-Changed-When: Sun Jan 15 02:22:13 PST 1995 
State-Changed-Why:  
This is not a bug.  The `'s are interpreted once when the string is read by 
the interpreter, so they need to be doubled.  When this is done, the program 
runs as it is apparently intended to. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.