Select and Copy to Multiple Lines

Select and Copy to Multiple Lines

1
NewbieNewbie
1

    Nov 10, 2006#1

    I have a file that contains multiple records ending with the text "START". I am looking for a way to perform a conditional select and paste if the line or lines below contain a 4-digit year at the end of the record. All fields are fixd length.

    Data Before:

    Afield1 Afield2 Afield3 START
    2005
    2006
    Bfield1 Bfield2 Bfield3 START
    2003
    2004
    2005
    2006
    Data After:

    Afield1 Afield2 Afield3 START
    Afield1 Afield2 Afield3 2005
    Afield1 Afield2 Afield3 2006
    Bfield1 Bfield2 Bfield3 START
    Bfield1 Bfield2 Bfield3 2003
    Bfield1 Bfield2 Bfield3 2004
    Bfield1 Bfield2 Bfield3 2005
    Bfield1 Bfield2 Bfield3 2006

    I would appreciate any help in writing a macro to perform this function.

    Thanks...

    6,684586
    Grand MasterGrand Master
    6,684586

      Nov 10, 2006#2

      Here is the macro which should do the job. It works with UE v11.20a for an ASCII file with DOS line terminations and configuration option Home Key Always Goto Column 1 checked (important if there are START lines with leading spaces/tabs).

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

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      TrimTrailingSpaces
      Clipboard 9
      Loop
      Find MatchCase RegExp "START$"
      IfNotFound
      ExitLoop
      EndIf
      Key Ctrl+LEFT ARROW
      StartSelect
      Key HOME
      Copy
      EndSelect
      Key DOWN ARROW
      StartSelect
      Find MatchCase RegExp Select "START$"
      IfSel
      Key HOME
      Else
      SelectToBottom
      EndIf
      Find RegExp "%^([0-9]+^)$"
      Replace All SelectText "^c^1"
      EndSelect
      EndLoop
      ClearClipboard
      Clipboard 0
      Top

      Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
      Best regards from an UC/UE/UES for Windows user from Austria