Iterate thru a list of files, each with its own find/replace criteria

Iterate thru a list of files, each with its own find/replace criteria

2
NewbieNewbie
2

    Jan 10, 2009#1

    I have a list of files, each with its own find/replace criteria. Here's what the list looks like:

    Format:
    folderX/sco.xml, findText, replaceText

    folder1/sco.xml, Subtraction Sense, Addition Facts
    folder2/sco.xml, Multiplying with Decimals, Adding with Decimals
    folder3/sco.xml, Numeration, Permutations and Combinations

    So for every file, I have a different find/replace scenario. Any ideas on how this might be handled in UltraEdit? I'm not familiar with this program, but it looks promising for this task.

    Thanks,
    Carey

    6,602548
    Grand MasterGrand Master
    6,602548

      Jan 10, 2009#2

      Best would be to do this with a script which can store strings in variables. That would make it possible to use the replace in files script command to do the replaces in the files without opening the files which is surely the fastest method.

      But script developing needs time, much more time than recording a macro and modify it a little to do the same job on every line of the list. I don't know how big your list is and how often you will run this macro in future. If needed only once, the macro is good enough. Otherwise it would be better to develop the script using the method I have written above.

      Here is the macro code without an explanation. You should not have any other file open in UltraEdit when you run this macro.

      The macro property Continue if search string not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Bottom
      IfColNumGt 1
      "
      "
      IfColNumGt 1
      DeleteToStartofLine
      EndIf
      EndIf
      Top
      Loop
      Find RegExp "%[~^r^n,]+"
      IfNotFound
      ExitLoop
      EndIf
      Clipboard 9
      Copy
      EndSelect
      Key RIGHT ARROW
      Key RIGHT ARROW
      Find RegExp "[~^r^n,]+"
      Clipboard 8
      Copy
      EndSelect
      Key RIGHT ARROW
      Key RIGHT ARROW
      Find RegExp "[~^r^n]+"
      Clipboard 7
      Copy
      EndSelect
      Clipboard 9
      Open "^c"
      Clipboard 7
      Paste
      SelectToTop
      Clipboard 8
      Find MatchCase "^c"
      Replace All "^s"
      IfNotFound
      CloseFile NoSave
      Else
      Delete
      CloseFile Save
      EndIf
      EndLoop
      Clipboard 9
      ClearClipboard
      Clipboard 8
      ClearClipboard
      Clipboard 7
      ClearClipboard
      Clipboard 0

      Attention: If your list file has not exactly the format as you have written in your post, you will get many files damaged. The format required for the macro is:

      name of the file with full path (without comma)commaspacesearch string (without comma)commaspacereplace string (without comma)end of line
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jan 10, 2009#3

        Wow, thank you so much. I haven't had time to test it yet, but I am very grateful for your reply.

        Carey