LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-28-2005, 04:55 AM   #1
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Rep: Reputation: 15
changing case in sed


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".
how can I do this with sed utility?

-- Mohammad
 
Old 08-28-2005, 07:28 AM   #2
Optimistic
Member
 
Registered: Jun 2004
Location: Germany
Distribution: Debian (testing)
Posts: 276

Rep: Reputation: 33
You could try the y switch.

Something like:

Code:
sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
 
Old 08-28-2005, 07:50 AM   #3
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Original Poster
Rep: Reputation: 15
how can I do this completely?
"m[A-Z].*" ---> "[a-z].*"
 
Old 08-28-2005, 08:17 AM   #4
Optimistic
Member
 
Registered: Jun 2004
Location: Germany
Distribution: Debian (testing)
Posts: 276

Rep: Reputation: 33
Instead of using sed why not use rename?

This will make all the filename lowercase:
Code:
 rename 'y/A-Z/a-z/' *
To get rid of the m, you could try (not so sure about this one):
Code:
rename 's/^m*/*/' *
 
Old 08-28-2005, 09:18 AM   #5
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Original Poster
Rep: Reputation: 15
Oh no I want to change variables names in c++ sources and header not change file names?!!
 
Old 08-28-2005, 02:49 PM   #6
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally posted by Optimistic
You could try the y switch.

Something like:

Code:
sed y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
Code:
sed 's/.*/\L&/'
is less to type! Vary the first pattern to match specifics rather than the whole line. \U to uppercase everything. Lowercase L or U will set the case of the first character matched.
 
Old 08-30-2005, 05:52 AM   #7
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Original Poster
Rep: Reputation: 15
I think I found my answer
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;
    float mFieldHeight;
    float mGoalWidth;
    float mGoalDepth;
    float mGoalHeight;
    float mBorderSize;

    float mAgentMass;
    float mAgentRadius;
    float mAgentMaxSpeed;
I got this as result:
Code:
 
    float fieldLength;
    float fieldWidth;
    float fieldHeight;
    float goalWidth;
    float goalDepth;
    float goalHeight;
    float borderSize;

    float agentMass;
    float agentRadius;
    float agentMaxSpeed;
It is right, but when I try to change this file
Code:
    while (msgRead < msgLen)
    {
        if (! SelectInput())
        {
            return false;
        }

        msgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
        offset += msgRead;
    }
I got this as result
Code:
    while (sgRead < msgLen)
    {
        if (! SelectInput())
        {
            return false;
        }

         sgRead += read(mReadFd, offset, sizeof(mBuffer) - msgRead);
        offset += sgRead;
    }
mistakes are made in red colored variables.
how can I fix it?
 
Old 08-30-2005, 06:56 AM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Why you don't use the example eddiebaby1023 gave?

Code:
This will change everything to lower case
cat file.txt | sed -e 's/.*/\L&/g'

And this will change all words that start with m
cat file.txt | sed -e 's/m.*/\L&/g'
 
Old 08-30-2005, 07:18 AM   #9
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Original Poster
Rep: Reputation: 15
I don't want to change case of all chars after m
I want to change
Code:
mFirstSecondThird
to
Code:
firstSecondThird
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help changing case on arguments to bourne shell script Maldain Programming 2 05-03-2005 10:18 AM
Converting sLoPPy cASE to Pretty Case with tr lowpro2k3 Programming 4 04-13-2005 08:13 PM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM
Lower case to upper case letter sudhasmyle Programming 1 12-03-2004 04:15 AM
Case sensitivity in SED substitutions jkoch Programming 1 02-21-2003 04:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration