[Top][All Lists]

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

Re: sed bug with options -ir

From: Paolo Bonzini
Subject: Re: sed bug with options -ir
Date: Wed, 31 Aug 2011 08:27:20 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0

On 08/30/2011 11:10 PM, Davide Brini wrote:
On Tue, 30 Aug 2011 21:33:34 +0200, David Watzke<address@hidden>  wrote:

Hi there,

I've encountered a strange bug in sed (or maybe it's not a bug and I'm
missing something here):

this command works fine and adds dashes between numbers:
sed -i -r "s/([0-9]+) ([0-9]+) ([0-9]+)$/\1-\2-\3/" mobily.txt

the file mobily.txt contains something like this (it's not important):
name surname 000 111 222

but the same command with -i and -r written in a short form like this
doesn't work:
sed -ir "s/([0-9]+) ([0-9]+) ([0-9]+)$/\1-\2-\3/" mobily.txt
sed: -e expression #1, char 39: invalid reference \3 on `s' command's RHS

Why is that?

It's not a bug. -i -r and -ir are NOT the same thing.

"-i -r" says "edit the file in place (pseudo), without making a backup (-i),
and use extended regular expressions (-r)".

"-ir" says "edit the file in place, and make a backup appending the
extension "r" to the original file name". So you may find a file
"mobily.txtr" in the same directory if the program ran successfully;
however, since you're not specifying -r anymore, the program fails because
it sees ERE syntax (in BRE, "(...)" are literal and do not create capture

Thanks Davide for the explanation!


reply via email to

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