Community
    • Login

    Search and Insert new line and Increment if line is missing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 693 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Harry HarrisH
      Harry Harris
      last edited by Harry Harris

      Hi All,
      I am wanting to search all files with a specific name (texture.cfg - I know how to do this!). I then want to see if a specific line is in these files i.e. fallback.??=…\texture\Planes_Generic. If the line does NOT exist then we need to add the line and increment the fallback.?? by one from the previous line. However some of the files are formatted “differently”. A couple of examples are:

      Example 1
      [fltsim]

      fallback.1=…\Asobo_208B_GRAND_CARAVAN_EX\texture
      fallback.2=…\texture\AS1000
      fallback.3=…\texture\Gauges
      fallback.4=…\texture\AS700
      fallback.5=…\texture\AS140
      fallback.6=…\texture\Extinguisher
      fallback.7=…\texture\Lights
      fallback.8=…\texture\Glass
      fallback.9=…\texture\DetailMap
      fallback.10=…\texture

      The next line needs to be:
      fallback.11=…\texture\Planes_Generic

      Example 2
      [fltsim]

      fallback.1=…\texture\AS1000
      fallback.2=…\texture\Gauges
      fallback.3=…\texture\AS700
      fallback.4=…\texture
      fallback.5=…\texture\AS140
      fallback.6=…\texture\Extinguisher
      fallback.7=…\texture\Lights
      fallback.8=…\texture\Glass
      fallback.9=…\texture\DetailMap
      fallback.10=…\texture

      fallback.11=…\Asobo_208B_GRAND_CARAVAN_EX\texture

      The next line needs to be:
      fallback.12=…\texture\Planes_Generic

      Is this sort of thing possible?

      TIA
      Hazza

      PeterJonesP Alan KilbornA 3 Replies Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Harry Harris
        last edited by

        @harry-harris ,

        You aren’t going to be able to do that with a normal Replace or Find in Files dialog box. The “increment” is meaningless to a regular expression, and cannot be done.

        There are examples in the forum of using the PythonScript plugin, and writing a script which will search the active file and do a “+1” replacement – search the forum for add_1 for examples of how to do that. There are also PythonScript examples of looping over a number of files in PythonScript plugin. Combine those two concepts into one script, and there you go.

        Give it a try yourself; if you get stuck, show us what you’ve tried so far, and show how the results aren’t matching what you expect them to.

        Harry HarrisH 1 Reply Last reply Reply Quote 0
        • Harry HarrisH
          Harry Harris @PeterJones
          last edited by

          @peterjones Thank you for the pointers! Will try this today.

          1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Harry Harris
            last edited by Alan Kilborn

            @harry-harris said in Search and Insert new line and Increment if line is missing:

            fallback.??=…\texture\Planes_Generic

            So you may need a bit of regular expression help here:

            • You want to search for a \ followed by a t but if you search for it the way you have written it you will not find that but rather you will be searching for a tab character as that is what the sequence \t means. You’ll want to use \\t instead.

            • You want to search for three . characters in a row, but . means something special to regular expressions. You’ll want to do \.\.\. or \.{3} instead. BUT SEE “LATE THOUGHT” BELOW.

            • To search for two digits in a row (where you have ??), you might want to do \d\d or \d{2}. ? is another special character to regular expressions.

            Putting it all together, where you had said:

            fallback.??=…\texture\Planes_Generic

            You probably should do:

            fallback\.\d\d=\.\.\.\\texture\\Planes_Generic

            LATE THOUGHT:

            Maybe from your data the three dots is really a Unicode ellipsis character. If that’s truly the case, maybe you can use it directly. It is hard to tell if it really is an ellipsis since you didn’t format your data appropriately when you posted, and the forum software may have manipulated it to be misleading.

            If you want to revise your posting to make it less misleading, you can follow directions HERE.

            1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Harry Harris
              last edited by Alan Kilborn

              @harry-harris

              If you need help getting started with PythonScript, you can find a bit of a quick-start HERE.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors