Loading ...
Sorry, an error occurred while loading the content.
 

Address the words before the 1st semicolon

Expand Messages
  • Roy Herring
    I have 2 types of lines in a file. One w/ 4 semicolons and one w/ 3 semicolons. I want to move the last word before the 1st semicolon to the beginning of the
    Message 1 of 2 , Dec 20, 2004
      I have 2 types of lines in a file. One w/ 4 semicolons and one w/ 3 semicolons.
      I want to move the last word before the 1st semicolon to the beginning of the line in both cases.

      The heart of the problem seems to be able to address the words before the 1st semicolon in a line of variable semicolons.

      Can anyone help?
      Thanks, Roy

      Input:
      First Last; Words2; Words3; Words4;
      First Middle Last; Words2; Words3;

      Desired output:
      Last First; Words2; Words3; Words4;
      Last First Middle; Words2; Words3;

      The following works for a line of 4 semicolons
      ^!REPLACE "^{.+}\s{\B*};{.+;.+;.+;}" >> "\2 \1;\3" rwsati

      The following works for a line of 3 semicolons
      ^!REPLACE "^{.+}\s{\B*};{.+;.+;}$" >> "\2 \1;\3" rwsati

      Together they do not work for both types of lines.


      [Non-text portions of this message have been removed]
    • Don - htmlfixit.com
      non-regular expression clip that does this: ;by don at htmlfixit.com ;Input: ;First Last; Words2; Words3; Words4; ;First Middle Last; Words2; Words3; ;Output:
      Message 2 of 2 , Dec 21, 2004
        non-regular expression clip that does this:

        ;by don at htmlfixit.com
        ;Input:
        ;First Last; Words2; Words3; Words4;
        ;First Middle Last; Words2; Words3;

        ;Output:
        ;Last First; Words2; Words3; Words4;
        ;Last First Middle; Words2; Words3;

        ;start of clip
        ^!Jump Doc_Start

        :Loop
        ^!ClearVariables
        ^!Select EOL
        ;split line on ;
        ^!SetListDelimiter ";"
        ; set array = to selection
        ^!SetArray %first_split%=^$GetSelection$
        ;split first data element (First [Middle] Last)
        ^!SetListDelimiter " "
        ; set array = to selection
        ^!SetArray %second_split%=^%first_split1%
        ;move Last to beginning of line
        ^!Set %first_split1%="^$StrReplace("
        ^%second_split^%second_split0%%";"";"^%first_split1%";False;False)$"
        ;the rebuild the first array element
        ^!Set %first_split1%="^%second_split^%second_split0%% ^%first_split1%"


        ;create loop to build complete line of output
        ^!Set %outCount%="1"
        :setOutput
        ^!Set %output%="^%output%^%first_split^%outCount%%;"
        ^!Inc %outCount%
        ^!If ^%outCount% < ^%first_split0% setOutput
        ;put output on clipboard and paste it over original
        ^!SetClipboard ^%output%
        ^!Paste
        ;jump to next line
        ^!Jump +1
        ;repeat til done
        ^!If ^$GetRow$ = ^$GetLinecount$ Next ELSE Loop
        ;if done say so
        ^!Info Done
      Your message has been successfully submitted and would be delivered to recipients shortly.