Sort all uppercase, first letter uppercase, all lowercase

Sort all uppercase, first letter uppercase, all lowercase

4
NewbieNewbie
4

    Nov 23, 2008#1

    Hello,
    I am new to the forum and had posted this query today morning but due to some glitch it has not appeared in the forum.

    My problem is simple. I have files with data in 3 formats:

    ALL UPPER CASE
    Only Initial Letter in Upper case
    all lower case.

    Example:
    AAA
    Abc
    aaa
    BBB
    Def
    bbb

    Using Ultraedit sort routine I get:
    AAA
    Abc
    BBB
    Def
    aaa
    bbb

    Whereas what I want is
    ALL UPPER CASE FIRST
    First letter in Upper case next and
    all lowercase at the end

    Example
    AAA
    BBB
    Abc
    Def
    aaa
    bbb

    Is there a macro to do this job? I work with huge files and cleaning them manually is getting painful. A macro would really help.

    Many thanks in advance

    Best rgrds,

    Boromir

    6,675585
    Grand MasterGrand Master
    6,675585

      Nov 24, 2008#2

      The following macro works on your small example.

      It first cuts all lines starting with not an uppercase character and collects them in clipboard 9.

      Next it cuts all lines starting with an uppercase character and the second character is not an uppercase character and collects them in clipboard 8.

      The remaining lines are those starting with 2 uppercase characters and empty lines. These lines are now sorted.

      The cutted lines starting with an uppercase character, but second character is not an uppercase character are pasted now from clipboard 8 into a new file, sorted and copied back into the source file below the already sorted lines (more or less) completely in uppercase.

      Same procedure is done next with the lines in clipboard 9 which do not start with an uppercase character. The new file is closed without saving.

      The result is what you asked for. I just can hope it works also for your huge files. That depends on how large your file really is and how much RAM you have to hold all the data in the clipboards.

      The macro property Continue if a Find with Replace not found or Continue if search string not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      IfColNumGt 1
      "
      "
      EndIf
      Top
      Clipboard 9
      ClearClipboard
      Loop
      Find MatchCase RegExp "%[~A-Z^p]*^p"
      IfFound
      CutAppend
      Else
      ExitLoop
      EndIf
      EndLoop
      Top
      Clipboard 8
      ClearClipboard
      Loop
      Find MatchCase RegExp "%[A-Z][~A-Z^p]*^p"
      IfFound
      CutAppend
      Else
      ExitLoop
      EndIf
      EndLoop
      Top
      SortAsc 1 -1 0 0 0 0 0 0
      NewFile
      Paste
      Top
      SortAsc 1 -1 0 0 0 0 0 0
      SelectAll
      Cut
      NextWindow
      Bottom
      Paste
      ClearClipboard
      Clipboard 9
      PreviousWindow
      Paste
      Top
      SortAsc 1 -1 0 0 0 0 0 0
      SelectAll
      Copy
      CloseFile NoSave
      Paste
      ClearClipboard
      Clipboard 0
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        Nov 24, 2008#3

        Mofi u r the greatest it works like a charm and too on very long files. I understood a major part of the macro but I couldn't get the following:
        SortAsc 1 -1 0 0 0 0 0 0
        What exactly does this function do?
        If you have time to explain it would be great.
        Many thanks once more. U r a lifesaver,

        Best regds,

        Boromir

        6,675585
        Grand MasterGrand Master
        6,675585

          Nov 25, 2008#4

          SortAsc 1 -1 0 0 0 0 0 0

          means sort whole file (or only the selected lines) ascending, case-sensitive and evaluate the entire line as sorting criteria. That command does the same as when you open File - Sort - Advanced Sort/Options, choose Ascending as sort order, uncheck all options and enter for Key 1 the value 1 for the start column and -1 for the end column which means end of line. For details see the help page for this dialog - press key F1 when dialog is open.
          Best regards from an UC/UE/UES for Windows user from Austria