More on counting upper case characters

(*This relates to a recent question I posted about counting upper case characters in a string. dev_sleidy responded with an applescript approach that works, but at 6 lines I was hoping for more compact code. So I played around with a one-line command line approach that so far seems reliable (tell me if you find it isn't). However, there are a couple peculiarities which I would like to understand. I know, I know, I should just shut up and use it. But I must be part cat and need to be killed.
The code that appears to work:*)
set T to "MY GraNd QuestioN A"
set UCcount to do shell script "echo " & quoted form of T & " | tr -d [[:space:]] | tr -d [:lower:] | wc -m"
(*The peculiarities:
1) If I substitute >>sed 's/ //g'<< for >>tr -d [[:space:]]<<, the result always seems to be one count high. (Same thing appears to happen when executed in Terminal.) Why?
2) When using regular expressions the format [[:class:]] has always worked for me, as it does for "space" in the code above. But for the second tr -d pipe (above code) those outside brackets mess everything up, and single brackets work fine. Same thing happens with both [[:lower:]] and [[:upper:]] but doesn't seem to happen when executed in Terminal. Why? Are there rules for bracketing character classes (I've seen different versions)?
Or is all this a UNIX forum question?*)

Hello
Honestly I don't understand why such result is returned by CODE1.
Its prototype [1] tested here works as expected.
But I noticed CODE2 may return wrong result, for its prototype [2] actually returns wrong result with MacPerl 5.6.1r2 under OS9.1 when input string is read from file insead of being given as string literal. I didn't test that possibility. Sorry for that. Please disregard CODE2, for I think CODE1 will be enough.
(The wrong result is caused by the fact that 'Ç' encoded in UTF-8 is counted as 2 chararcters by length function if it is read from file due to certain limitation of MacPerl 5.6.1r2. I don't know whether that applies to recent Perl under OSX.)
[1]
use utf8;
while (<>){
s/[^[:upper:]]//g;
} continue {
print;
[2]
use utf8;
local $/;
while (<>){
s/[^[:upper:]]//g;
print length;
Re. your original question about peculiarities.
As for 1), I think it is because 'echo' is adding trailing \n and "sed 's/ //g'" won't remove it. Try "sed 's/[[:space:]]//g'"  instead. Indeed "sed 's/[^[:upper:]]//g' will remove all non-upper case letters at once, I guess.
As for 2), I think it is because 'tr' actually does not process regexp. Its character class support is based upon POSIX but the usage is different from regexp, i.e. [:class:] in 'tr', while [[:class:]] in proper regexp. Meanwhile, I think, the regexp syntax, [[:class:]], in 'tr' argument works in Terminal because in Terminal, 'bash' processes the regexp in its parameter expansion (path name expansion, in this case) and 'tr' receives the expanded result as its argument.
cf.
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/tr.1.htm l
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/bash.1.h tml
Hope this may be of some help,
H

Similar Messages

  • Counting upper case characters

    set T_ to "My Grand Question"
    set T_cnt to count T_ --> 17
    Straightforward way to count the upper case characters of T_? A simple "do shell script" approach would be fine.

    set tString to "My Grand Question"
    set cString to 0
    repeat with i in tString
    set aNumber to ASCII number i
    if ((aNumber > 64) and (aNumber < 91)) then set cString to cString + 1
    end repeat
    cString

  • Firefox does not recognize upper case characters on my keyboard, when i try to log in on a saved website with a case-sensitive user/password. repeated Capslock on, then off, or Shift on, then off, sometimes corrects. thx

    this happens almost every time I get onto my computer. doesn't happen when using Explorer

    Greetings NoNameGiven,
    If I understand the problem correctly (I’m not sure I do) you would prefer ‘iii’ to be read as “eye eye eye” rather than “three”? The alt text property is the only way that I know of to make this happen. Hope this helps.
    a ‘C’ student

  • Special characters converted in wrong in Upper case ?

    Hello,
    In material description , some characters such as µ when converted into upper case it will be 'M' in stead of 'µ' . This is in SAP ECC unicode . But it's ok in R/3.
    So in this case, Is there any solution for this problem ?
    Thanks

    MAKT-MAKTG : For upper case characters , When our client search for values when pressing F4 in material , If there's material description that contain 'u03BC', It will be displayed as 'M' in the text . This will happen in ECC 6 not in R/3 ( in R/3 two texts are the same) .
    The different behavior you're observing between what you call R/3 and ECC 6 is not due to the different releases, but based on the fact that one system is Unicode enabled and the other not. I suspect that you are most likely logging onto the system with a language that's linked to code page 1100 (in the non-Unicode release). Code page 1100 is similar to the Latin-1/ISO-8859-1 code page, which is designed to have most characters for western languages, but does not contain all Greek letters (SAP would most likely use code page 1700 if you set a greek locale).
    Again, it may sound silly, but you have to distinguish between the symbol µ (Unicode code point U+00B5) and the lower case greek letter u03BC (U03BC). SAP code page 1100 contains only the symbol µ (U00B5), which represents the prefix micro as for example in 1µm = 1 micro meter = 0.000001m. Neither the greek lower case letter u03BC (U+03BC) nor it's corresponding upper case letter exists in code page 1100.
    The Unicode standard defines the greek upper case letter u039C (U039C) as the upper case to use for both the symbol  µ (U00B5) and the lower case greek letter u03BC (U+03BC), see for example the Unicode mapping chart for Greek (so that's why you see a different behavior in ECC 6).
    I'm not sure why, but for some reason SAP found it worthwhile mentioning that they actually also convert the symbol  µ (U00B5) to u039C (U039C), though that essentially just means following Unicode standard. Anyhow, if you're interested in further details, check out OSS note 1078295 - Incomplete to upper cases in old code pages.

  • Small caps - is there a way to change size ratio of lower to upper case?

    I am using Adobe InDesign CS4 and one problem I've had is that when I select Small Caps on the character styles panel, lower case characters are about 60% the size of upper case characters. I'd like this to be more around 80% in my document.
    I don't see a way to do this, so I'm having to avoid using Small Caps and am having to select various portions of each word and set them to different sizes.
    Is there a setting I am missing for Small Caps that would save me this trouble? My typeface is Minion so I may also see if there's a variant available that uses well-crafted small caps.
    Tim

    Dave,
    >.. adjust the size of the "lowercase" characters by using a GREP style
    Yes ... and no.
    It doesn't have to be an extremely complicated GREP style. You mention Unicode ranges, but it's not even necessary. You could try
    >[a-z]
    to select all lowercase characters, but it leaves out accented ones. Now specifying ranges for these doesn't work very good (to put it mildly), because they do not appear consecutively in the Unicode set.
    Fortunately, GREP has a wildcard
    >\l
    for "lowercase", and this matches
    i every
    lowercase character (even Greek and Russian ones). It's equal to the POSIX expression
    >[[:lower:]]
    As this seems to work just the way you want, then why the "No"? The GREP style will be applied to
    i all
    lowercase characters in the paragraph, not just to the words you wanted.
    [Warning: Dirty trick follows. Do Not Copy Unless Forced To.]
    Of course you can
    i force
    the GREP style pick up 'unique' words by making them unique somehow. If you insert an invisible character
    i before
    and
    i after
    the words you want to mark -- in the case at hand, the ones you want to small-capitalize --, you can include the invisible characters in the GREP style. For example, by specifying
    >~-\l+~-
    you can "mark" words by inserting a soft hyphen before and after certain words. (This example also presumes only lowercase characters inbetween.) You don't have to use the soft hyphen, there are a couple more markers you could (ab)use. I think I'll leave it up to your imagination to wonder where it could possibly go wrong.

  • Issue with upper case in cyrillic characters - error with SID generation

    Hi all,
    I have a problem loading a cyrillic string into a characteristic in a DSO.
    I get an error message when trying to activate the data in the DSO.
    The characteristic is a CHAR18 with the "lowercase letters" unmarked and there is an abap
    routine to convert the string in upper case.
    According to the error message, the string seems to be converted because the error shows the string in upper case ( the input was in lower case)  but the DSO data is not activated:
    " Value 'НЕУСТОЙКА 3498' (hex. '041D0415042304210422041E0419041A041000200033003400')
    of characteristic A2_ALLOCN contains invalid characters",
    I am working in an unicode system and I don´t know what is wrong...
    Any input will be highly appreciate it.
    Thanks in advance,
    Elena

    Value 'НЕУСТОЙКА 3498'
    Seems to be value contains invalid character.  Й
    If you need to populate invalid char into target  maintain this in t- code RSKC , Then system allows the Invalide chars into the target
    Donu2019t need edit this ivalue manually in PSA with required value and reconstruct from PSA.
    With Regards,
    Kishore.
    Edited by: Siv Kishore on Apr 22, 2009 11:37 AM
    Edited by: Siv Kishore on Apr 22, 2009 11:39 AM

  • Upper or Lower Case Characters

    Hi everyone:
    I know this may sound silly, but I am new at this so be nice!
    When creating an address for your webpage, do the charcters
    have to be upper case or lower case. I know that I have seen some
    web addresses with both upper and lower case.

    I think she means domain name. In that case, it doesn't
    matter. There's no
    upper case in domain names.... As far as I know.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Alan" <[email protected]> wrote in
    message
    news:C0B5DC49.292429%[email protected]..
    > do you mean file and folder names?
    >
    > You can use what you want-
    > Something to be aware of, unix/linux servers (which are
    the majority of
    > hosting) are case-sensitive. If you name a file
    BoxTop.HTM and link to it
    > as boxtop.htm the link will not find the file.
    >
    > I would suggest a conservative file and folder naming
    convention to avoid
    > possible problems. Lower-case a-->z and 0-->9
    only. No blank spaces, no
    > punctuation or other things.
    >

  • Capitalization doesn't work as described. One can start with lower case and change to upper, but changing from upper case to any of the other options doesn't work. Is there a way around this or is this just a glitch that needs fixing?

    In Pages capitalization doesn't work as described. One can start with lower case and change to upper, but changing from upper case to any of the other options doesn't work. Is there a way around this or is this just a glitch that needs fixing?

    I think it does work as described, but the description is not very complete. Capitalization does not change any of the characters that you type; what it does is allow some of the lower case characters to display as capitals. If you copy the result and paste it as plain text, you'll see that the lower case characters are still there. It doesn't actually say anywhere that it can make capitals display as lower case, and it can't.
    The obvious way around this is to actually type what you want.
    The more powerful way is to install WordService from Devon Technologies which adds the functionality of Pages' capitalization menu as well a lot of other ones. WordService actually changes the character to the one displayed, and it works in most of the applications on your Mac.

  • Convert mixed case value in colum into upper case values

    Hi All,
    I have got a table call emp and has the following colums:
    id number 10
    suename_name varchar2(20)
    given_name varchar2(20)
    position varchar2(30)
    date_hired date
    Now the values in colums are mixed case and I need to change them to upper case. I think I need to use upper function to do it.
    Could anyone help me by providing me sql/pl sql script to through each colum in emp table and change them to the upper case.
    Many Thanks
    Michael

    Hi,
    If you really want to try this using PL/SQL, then you'll have to use dynamic SQL, something like this untested code, since the table and column names are vaiable:
    SET   SERVEROUTPUT  ON  SIZE 50000
    DECLARE
         sql_txt     VARCHAR2 (4000);
    BEGIN
         FOR  r  IN ( SELECT  table_name
                   ,       column_name
                   FROM    user_tab_columns
                   WHERE   data_type = 'VARCHAR2'
              --   AND     ...  -- if you don't want all columns in all tables
         LOOP
              sql_txt := 'UPDATE "'
                   || r.table_name
                   || '" SET "'
                   || r.column_name
                   || '" = UPPER ("'
                   || r.column_name
                   || '")';
              dbms_output.put_line (sql_txt || ' = sql_txt');     -- For debugging
              -- EXECUTE IMMEDIATE sql_txt;               -- For real
         END LOOP;
    END;Dynamic SQL (here) means creating a string that contains the SQL statement to be done, then using EXECUTE IMMEDIATE to run it.
    Whenever you write dynamic SQL, it's a good idea to only display the SQL statement during the early stages of debugging. When it's displaying correctly, then you can try un-commenting the EXECUTE IMMEDIATE line.
    Edited by: Frank Kulash on Jul 19, 2009 4:40 PM
    A little more complicated, but a lot more efficient:
    SET   SERVEROUTPUT  ON  SIZE 50000
    DECLARE
         sql_txt          VARCHAR2 (4000);
    BEGIN
         FOR  r  IN ( SELECT    table_name
                   ,         column_name
                   ,         ROW_NUMBER () OVER ( PARTITION BY  table_name
                                      ORDER BY       column_name
                                    )     AS column_num
                   ,            COUNT (1)     OVER ( PARTITION BY  table_name
                                    )     AS total_column_cnt
                   FROM      user_tab_columns
                   WHERE     data_type = 'VARCHAR2'
              --   AND       ...  -- if you don't want all columns in all tables
                   ORDER BY  table_name
                   ,            column_name
         LOOP
              IF  r.column_num = 1
              THEN
                   sql_txt := 'UPDATE "'
                   || r.table_name
                   || '" SET "';
              ELSE
                   sql_txt := sql_txt || ', "';
              END IF;
              sql_txt := sql_txt ||
                   || r.column_name
                   || '" = UPPER ("'
                   || r.column_name
                   || '")';
              IF  r.column_num = r.total_column_cnt
              THEN     -- This is the last row for this table; run it
                   dbms_output.put_line (sql_txt || ' = sql_txt');     -- For debugging
                   -- EXECUTE IMMEDIATE sql_txt;               -- For real
              END IF;
         END LOOP;
    END;
    {code}
    The difference is that the first solution produces and executes a separate UPDATE statement for each column, like this:
    {code}
    UPDATE "TABLE_1" SET "COLUMN_A" = UPPER ("COLUMN_A");
    UPDATE "TABLE_1" SET "COLUMN_B" = UPPER ("COLUMN_B");
    UPDATE "TABLE_1" SET "COLUMN_C" = UPPER ("COLUMN_C");
    {code}
    but it's much more efficient to do change all the columns at once, as long as you have the row in hand.  So the second solution only creates one SQL statement per table, like this:
    {code}
    UPDATE "TABLE_1" SET "COLUMN_A" = UPPER ("COLUMN_A")
               ,   "COLUMN_B" = UPPER ("COLUMN_B")
               ,   "COLUMN_C" = UPPER ("COLUMN_C");
    {code} where every line above corresponds to a row fom the query.  The first line for every table will start with
    {code}
    UPDATE "TABLE_1" SET "but all the others will start with
    {code}
    and only on the last column for a given table will the statement be executed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • "why the Psoft oracle DB and SID names should be in all upper case

    Customer is having a Question like
    "why the Psoft oracle DB and SID names should be in all upper case (according to the PsoftTools 8.50 Installation for Oracle manual)
    why the Peopletools 8.5 install book states all Oracle SID and database names should be in UpperCase.
    If we use lower case database name, would encounter any problems, what sort of problems?
    i Observed that all the Installation manual for 8.49,50,51 States the Same for Creating of Data base !
    Task 1-6-1: Determining Databases and Database Names
    You should also determine the names of the
    databases at this point, using database names that:
    • Are limited to eight characters, all UPPERCASE.
    • Capture information about the PeopleSoft product line and the type of database
    Please suggest on this !
    Thanks
    Bala

    user13798675 wrote:
    Customer is having a Question like
    "why the Psoft oracle DB and SID names should be in all upper case (according to the PsoftTools 8.50 Installation for Oracle manual)
    why the Peopletools 8.5 install book states all Oracle SID and database names should be in UpperCase.
    If we use lower case database name, would encounter any problems, what sort of problems?
    i Observed that all the Installation manual for 8.49,50,51 States the Same for Creating of Data base !
    Task 1-6-1: Determining Databases and Database Names
    You should also determine the names of the
    databases at this point, using database names that:
    • Are limited to eight characters, all UPPERCASE.
    • Capture information about the PeopleSoft product line and the type of database
    Please suggest on this !
    Thanks
    Balabcm@bcm-laptop:~$ env | grep ORA
    ORACLE_SID=v112
    ORACLE_BASE=/u01/app/oracle
    ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    bcm@bcm-laptop:~$

  • How to disable Automatic UPPER case in SQL Developer

    Hi,
    I am using SQL developer more than two years. I have recently downloaded SQL Developer 2.1.1.64.
    My problem is, while editing the package body when move to newline the previous line get converted to UPPER case automatically. But, I don't want to get all the code I have written to be converted to UPPER case.
    I have tried all possible preference changes but no change. Can you please help me how disable the case change in SQL developer.
    Looking forward your response.
    Thanks,
    Prashantha Konkodi

    You can always define how you want to format the SQL or normal text by using the keyboard CTRL+' to manage text/keyword case to all UPPERCASE, Initcap, or all lowercase.
    The system remembers your settings and will keep the text the same format in future.

  • Conditional Upper Case formatting

    Hi there, I need to be able to format the first letter of a word upper case or lower case depending upon whether or not it appears at the start of a sentence. There must be a method of doing this using the String class. Any ideas folks? All contributions greatly appreciated!

    It's a remarkably difficult problem to determine whether a sequence of chars constitutes a word, and what constitutes a sentence, especially considering that Java strings can be used to contain text in not only English but also Thai and Inuktitut and Coptic and all of the world's written languages. So perhaps it isn't all that surprising that the language designers didn't feel it necessary to solve that problem within the String class.
    However if you have a more restrictive problem domain then perhaps you have an easier problem.

  • How to convert lower case to upper case?

    Hi,
    How to convert lower case letter to upper case and vice versa?

    TRANSLATE
    Variants:
    1. TRANSLATE c TO UPPER CASE.
    2. TRANSLATE c TO LOWER CASE.
    3. TRANSLATE c USING r.
    See String processing
    Variant 1
    TRANSLATE c TO UPPER CASE.
    Variant 2
    TRANSLATE c TO LOWER CASE.
    Effect
    The first variant converts all lowercase letters in c to uppercase. The second variant converts all uppercase letters to lowercase.
    Example
    DATA letters(3) TYPE C.
    MOVE 'abc' TO letters.
    TRANSLATE letters TO UPPER CASE.
    letters now has the contents 'ABC'.
    Note
    The classification of upper- and lowercase, and the actual characters used are determined by the current text environment (see SET LOCALE LANGUAGE). Problems may occur when the system converts the characters, if the wrong language has been specified in SET LOCALE LANGUAGE, or if data has been processed that does
    Variant 3
    TRANSLATE c USING r.
    Effect
    Replaces all the characters in the field c according to the rule in field r. c1 containscharacter pairs. The second character in each pair replaces the first. If r does not contain a character in c, this character remains unchanged. r can also be a variable.
    Example
    DATA: letters(20) TYPE C VALUE 'abcabcabcXab',
          change(15)  TYPE C VALUE 'aXbaYBabZacZ'.
    TRANSLATE letters USING change.
    letters now contains 'XaZXaZXaZXXaZ'.
    REWARD IF USEFUL

  • Translate to Upper Case in Transformation

    Hello BI experts,
    Extractor has more than 100 fields in combination of Char, Num, Date etc...
    Some Char fields are bringing data in lower case letters. 
    Here I am looking for ABAP code in Start routine, where I can translate all Char fields lower case letter to Upper case.
    I know how to translate for each individual field level (infoobject routine level).  But I need in Start routine for all Char fields at once.  In other words,  I think, we have to filter out Char fields from <Source-Fields> and translate them to Upper case.
    Any help would be greatly appreciated.
    Thanks much,
    Anil

    Hi,
    try the following logic in start routine& let me know if you find any difficulty..
    data : r_itab type table of rstrucinfo,
              v_sytabix like sy-tabix,
              wa type rstrucinfo.
        FIELD-SYMBOLS : <fs1> type any,
                     <fs2> type any.
        CALL FUNCTION 'GET_COMPONENT_LIST'
          EXPORTING
            program    = sy-repid
            fieldname  = 'SOURCE_PACKAGE'
          TABLES
            components = r_itab[].
        loop at SOURCE_PACKAGE assigning <fs2>.
          v_sytabix = sy-tabix.
          loop at r_itab into wa where TYPE = 'C'.
            assign component wa-COMPNAME of structure <fs2> to <fs1>.
            translate <fs1> to upper case.
          endloop.
          modify SOURCE_PACKAGE from <fs2> index v_sytabix.
        endloop.
    regards,
    raju

  • 1.5GHz upper case on a 1.67 GHz?

    Dear Apple Discussions,
    the upper case for my 1.67 GHz (High Res.) PowerBook G4 has some cosmetic damage. I was wondering if I could replace it with the upper case of a 1.5 GHz PowerBook G4?
    The main concern I have is in regards to the trackpad not working since I vaguely remember reading Apple changed manufacturers (which is why the third party iScroll would not work on my machine).
    Any thoughts would be appreciated

    The high-res PowerBook G4 1.67GHz utilizes a different top case according to a dealer on eBay that specializes in Mac parts. I bought something from him recently and asked him about the top cases for the PowerBooks and he says that the 1.67GHz top case has different circuitry.
    The top case for the 1.5GHz/1.67GHz (models A1106) are interchangeable. I bought one of these for my 1.5GHz that I'm typing from right now. But these can't be used on the high-res 1.67GHz (and can't be used on earlier 1.5GHz or previous models). This is the info I have:
    A1106 (1.5GHz/1.67GHz)
    Apple Part No. 922-6920, Assembly No. 620-3030
    A1138 (1.67GHz HR DLSD)
    Apple Part No. 922-6920, Assembly No. 620-3273
    Message was edited by: Pismo 900
    Also, I found this "more reliable" info from iFixIt.com who also points out that there are two different case parts for the two machines, though the part no. is different.
    1.67GHz A1106
    [http://www.ifixit.com/PowerBook-Parts/G4-Aluminum-15-Inch-1-5-1-67-GHz-Upper-Ca se/IF154-058]
    1.67GHz A1138
    [http://www.ifixit.com/PowerBook-Parts/G4-Aluminum-15-Inch-1-67-GHz-HR-Upper-Cas e/IF164-005]
    Message was edited by: Pismo 900
    Also, just to note, the keyboards are different as well. This one I learned first-hand after buying a brand new keyboard for my 15-incher and it belonged to the high-res 1.67GHz model, to my dismay. (The seller noted the wrong part no.-- he said it was for the 1.5GHz/1.67GHz models, and when I cross referenced that part no. on Google, I found it belonged to the high-res 1.67GHz)

Maybe you are looking for