bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] 9g)sub() bug?


From: Davide Brini
Subject: Re: [bug-gawk] 9g)sub() bug?
Date: Tue, 16 Aug 2011 15:05:05 +0200

On Tue, 16 Aug 2011 14:46:09 +0200 (CEST), address@hidden wrote:

> 
> 
> Hello, 
> 
> consider the following gawk code: 
> 
> gawk 'END { line="@defn bibtex++" ; sub("bibtex++",
> "\\textup{\\texttt{bibtex++}}", line) ; print line}' </dev/null 
> 
> This gives: 
> 
> @defn \textup{\texttt{bibtex++}}++ 
> 
> Where are those last 2 trailing ++'s coming from?

From the ERE standard: "The behavior of multiple adjacent duplication
symbols ( '+' , '*' , '?' , and intervals) produces undefined results".

"+"is a special character in awk's regular expressions.

Escape the "+"'s and you'll be fine:

$ gawk 'END { line="@defn bibtex++" ; sub("bibtex\\+\\+",
"\\textup{\\texttt{bibtex++}}", line) ; print line}' </dev/null
@defn \textup{\texttt{bibtex++}}

or better yet use regexp literals to avoid escaping hell:

$ gawk 'END { line="@defn bibtex++" ; sub(/bibtex\+\+/, 
"\\textup{\\texttt{bibtex++}}", line) ; print line}' </dev/null
@defn \textup{\texttt{bibtex++}}

-- 
D.



reply via email to

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