Mohammad Moghimi | 1 Sep 2005 21:22
Picon

m[A-Z].* --> [a-z].*

Hi
I have some sources with this member fileds style

code:

m[A-Z].*

 
I want to convert them to 

code:

[a-z].*

for example if a field named "mTime" I want to change it to "time".

I tried this:
code:

sed 's/\<m\([A-Z]\)/\l\1/'

 
but I don't know why this does wrong.
When I run it on this file:

code:

    float mFieldLength;
    float mFieldWidth;

(Continue reading)

Tim Chase | 1 Sep 2005 22:03

Re: m[A-Z].* --> [a-z].*

> sed 's/\<m\([A-Z]\)/\l\1/'
[cut]
>         msgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
[cut]
>          sgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);

Are you sure you used the same Sed expression?  I copied your 
code example into a file and ran it through

	sed 's/\<m\([A-Z]\)/\l\1/g'

getting back just what I'd expect:

   tim <at> scoria:~/temp$ diff x <(sed 's/\<m\([A-Z]\)/\l\1/g' x)
   9c9
   <  msgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
   ---
   >  msgRead += read(readFd, offset, sizeof(buffer) - msgRead);

(adjusted the spacing to make it fit on one line)

It looks like (from your results) that you may have omitted the 
\(...\) portion or its contents.

Additionally, you might want to make *all* the changes on each 
line, which is indicated by the "g" flag at the end.

There might be something peculiar with your version of sed too. 
I tried the above with GNU Sed (4.1.2) from bash, running on 
Debian.  Which version, and on which platform (and if germane, 
(Continue reading)

Mohammad Moghimi | 1 Sep 2005 22:20
Picon

Re: m[A-Z].* --> [a-z].*

I ran it on SuSE 9.3, with sed 4.1.4 from bash.
I run it again
sed 's/m\([A-Z]\)/\l\1/g' x.cpp
and the same result. I expect 
mReadFd --> readFd
msgRead --> msgRead (leave unchanged)
but I get
mReadFd --> readFd
msgRead --> sgRead

On 9/1/05, Tim Chase <sed <at> thechases.com> wrote:
> 
> > sed 's/\<m\([A-Z]\)/\l\1/'
> [cut]
> > msgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
> [cut]
> > sgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
> 
> Are you sure you used the same Sed expression? I copied your
> code example into a file and ran it through
> 
> sed 's/\<m\([A-Z]\)/\l\1/g'
> 
> getting back just what I'd expect:
> 
> tim <at> scoria:~/temp$ diff x <(sed 's/\<m\([A-Z]\)/\l\1/g' x)
> 9c9
> < msgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
> ---
> > msgRead += read(readFd, offset, sizeof(buffer) - msgRead);
(Continue reading)

Paolo Bonzini | 2 Sep 2005 08:33
Picon

Re: m[A-Z].* --> [a-z].*


>There might be something peculiar with your version of sed too. 
>I tried the above with GNU Sed (4.1.2) from bash, running on 
>Debian.  Which version, and on which platform (and if germane, 
>which shell) are you running the command?
>  
>
I remember fixing a bug in \l some time ago, but I can't recall when 
exactly.  Surely 4.1.* are ok, and the testcase (testsuite/flipcase.* in 
the sed distribution) has lines such as these:

09 - 02 - 2002 00.00 Tg La7 La7 -
09 - 02 - 2002 00.00 Brand New Tmc 2 -
09 - 02 - 2002 00.10 Tg1 Notte Rai Uno -

So it looks like I fixed it in 2002 (even with a slack of a few months 
between bug report and fix...)

Paolo

------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~-> 

--

-- 

Yahoo! Groups Links

<*> To visit your group on the web, go to:
(Continue reading)

Paolo Bonzini | 2 Sep 2005 08:35
Picon

Re: m[A-Z].* --> [a-z].*

Mohammad Moghimi wrote:

>I ran it on SuSE 9.3, with sed 4.1.4 from bash.
>I run it again
>sed 's/m\([A-Z]\)/\l\1/g' x.cpp
>and the same result. I expect 
>mReadFd --> readFd
>msgRead --> msgRead (leave unchanged)
>but I get
>mReadFd --> readFd
>msgRead --> sgRead
>  
>
It looks like the same old "feature" of POSIX regex, that [A-Z] is 
matched with strcoll rather than strcmp. :-(  So depending on the 
locale, strcoll may be case-insensitive.  This sucks, I know, but 
there's no way I can fix it.

The "fix" is to install sed as, say, gsed, and put a script like this as 
/bin/sed:

#! /bin/sh
LANG=C LC_ALL=C LC_COLLATE=C exec /bin/gsed "$ <at> "

Paolo

------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~-> 
(Continue reading)

kaushik.m | 6 Sep 2005 10:25
Favicon

doubt regarding sed behaviour


hi , 
        I have a doubt in a question  regarding use of sed .
The question is : what will be the output of the command  : echo "[fred]" 
| sed "s/[*fred]*/john/" 

and why so ?

regards,
Kaushik 

Notice: The information contained in this e-mail message and/or attachments to it may contain
confidential or privileged information.   If you are not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the information contained in this e-mail message and/or
attachments to it are strictly prohibited.   If you have received this communication in error, please
notify us by reply e-mail or telephone and immediately and permanently delete the message and any
attachments.  Thank you

[Non-text portions of this message have been removed]

------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~-> 

--

-- 

Yahoo! Groups Links

<*> To visit your group on the web, go to:
(Continue reading)

Ruud H.G. van Tol | 6 Sep 2005 10:57
Picon

Re: doubt regarding sed behaviour

kaushik.m <at> tcs.com schreef:

> what will be the output of the command:
> echo "[fred]" | sed "s/[*fred]*/john/"

The ouptput will be:

  john[fred]

because the [] in the sed-command contains a character class, so the
[...]* matches a nothing, and the first nothing is at the start of the
line.

Try:

  echo "[fred]" | sed "s/\[*fred]*/john/"

-- 
Grtz, Ruud

------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~-> 

--

-- 

Yahoo! Groups Links

<*> To visit your group on the web, go to:
(Continue reading)

kaushik.m | 6 Sep 2005 11:18
Favicon

Re: doubt regarding sed behaviour


hi Ruud,
        Thank you for your reply.
But i am still a bit unclear about the purpose of the brackets in the 
beginning of the [] brackets i.e [*fred].

Could you please explain this step by step ?

Thanks in advance

Kaushik 

"Ruud H.G. van Tol" <rvtol <at> isolution.nl> 
Sent by: sed-users <at> yahoogroups.com
09/06/2005 02:27 PM

To
"[sed-users]" <sed-users <at> yahoogroups.com>
cc

Subject
Re: doubt regarding sed behaviour

kaushik.m <at> tcs.com schreef:

> what will be the output of the command:
> echo "[fred]" | sed "s/[*fred]*/john/"

The ouptput will be:

(Continue reading)

Ruud H.G. van Tol | 6 Sep 2005 12:35
Picon

Re: doubt regarding sed behaviour

kaushik.m <at> tcs.com schreef:

> i am still a bit unclear about the purpose of the brackets in the
> beginning of the [] brackets i.e [*fred].
>
> Could you please explain this step by step ?

No, here is not the place for that.

Use google: regular.expressions character.class

(with the embedded dots)

Also read the manpage of re_format, as listed in the SEE ALSO section of
the manpage of sed.

-- 
Grtz, Ruud

------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~-> 

--

-- 

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/sed-users/
(Continue reading)

Tim Chase | 6 Sep 2005 14:59

Re: doubt regarding sed behaviour

> But i am still a bit unclear about the purpose of the brackets
> in the beginning of the [] brackets i.e [*fred].
> 
> Could you please explain this step by step ?

Stuff contained in square brackets is considered a single atom. 
Your regexp breaks down as

[...]*      If you find zero or more of any of the characters
             contained in the brackets
/john/      replace them with the word "john"

Beginning with your input:

	[fred]

before the first character is reached, you have successfully 
matched *zero* of those characters, so it replaces them with the 
word "john", yielding

	john[fred]

because you only specified the first match (no "g"lobal 
modifier).  Behavior might be even more confusing if you *do* 
specify the "g"lobal modifier, as you get

	john[john]john

This is because you have your first match (as above), then it 
finds the "[" which doesn't match, so it just passes it on 
(Continue reading)


Gmane