Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Renaming multiple names?

    Help wanted · · · – – – · · ·
    4
    5
    143
    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.
    • Ozzy Neil
      Ozzy Neil last edited by

      Hi, I was wanting to rename the drivers in a json file and was wondering Is it possible to select multiple “driverName” “Names” and then paste in copied names from another text file. I will be doing this alot and up to 40 names at once, so the quicker the better.
      eg. the following Jaime Baker / Steven Kourepenos / Jeff Rubin

      renamed to Craig Lowndes / Mark Skaife / Russell Ingall

      {
      “drivers”: [
      {
      “driverName”: “Jaime Baker”,
      “carDesign”: “21,fa7fed,000000,ffffff,fa7fed”,
      “carNumber”: “1”,
      “suitDesign”: “1,fa7fed,000000,ffffff”,
      “helmetDesign”: “1,fa7fed,000000,ffffff”,
      “carPath”: “mx5\mx52016”,
      },
      {
      “driverName”: “Steven Kourepenos”,
      “carDesign”: “0,111111,cccccc,ed1c24”,
      “carNumber”: “2”,
      “suitDesign”: “13,111111,cccccc,ed1c24”,
      “helmetDesign”: “63,111111,cccccc,ed1c24”,
      “carPath”: “mx5\mx52016”,
      },
      {
      “driverName”: “Jeff Rubin”,
      “carDesign”: “9,ffffff,1a4b9b,dff000”,
      “carNumber”: “3”,
      “suitDesign”: “23,ffffff,1a4b9b,dff000”,
      “helmetDesign”: “35,ffffff,1a4b9b,dff000”,
      “carPath”: “mx5\mx52016”,

      Cheers, Neil.

      Ekopalypse 1 Reply Last reply Reply Quote 0
      • Ekopalypse
        Ekopalypse @Ozzy Neil last edited by Ekopalypse

        @Ozzy-Neil

        Is it possible to select multiple “driverName” “Names” and then paste in copied names from another text file

        No, if it is meant to be like this
        Having the names bob, john, sue in one file, select all and press copy
        and in the other file you might select the names tim, nancy, susan and
        you want to replace tim with bob, nancy with john and susan with sue.

        Yes, if you are willing to install a scripting language like python script
        and the process of selection and copy follows a strict rule

        Yes if you want to use regular expression and you either are willing
        to learn how it works, in case the file where the names are to be replaced
        is looking different each time you want it to do,
        or getting it done once right if the file looks always the same.

        Let us know if you want to go one of the mentioned ways.

        Ozzy Neil 1 Reply Last reply Reply Quote 1
        • Ozzy Neil
          Ozzy Neil @Ekopalypse last edited by

          @Ekopalypse Was hoping for the first option, My knowledge on such thigs is zero, so thanks for the reply, i’ll give it a miss.

          Alan Kilborn 1 Reply Last reply Reply Quote 0
          • Alan Kilborn
            Alan Kilborn @Ozzy Neil last edited by Alan Kilborn

            @Ozzy-Neil said in Renaming multiple names?:

            the first option

            The problem with wanting that – well, not really the wanting (you are free to want anything your heart desires) – is that it is very specific to your exact need, and thus won’t be supported by any general purpose tool. Of course, if you write code, you can go ahead and code up your very specific need.

            So, barring you writing that specific code, if you still need to accomplish your goal, I suggest you be flexible and consider the possibility of the other options (with a “Yes, if…”) that were offered. Sure, they are probably more complicated to use than your desired solution, but that’s the nature of it.

            1 Reply Last reply Reply Quote 3
            • guy038
              guy038 last edited by

              Hello, @ozzy-neil, @Ekopalypse, @alan-kilborn and All,

              From that link, below, giving the general structure of the JSON language :

              https://www.json.org/json-en.html

              Here is a work-around, using a regex S/R :

              • First, at the very end of your JSON file, add this new JSON object, below :
              {
              "Steven Kourepenos": "Mark Skaife",
              "Jeff Rubin": "Russell Ingall",
              "Jaime Baker": "Craig Lowndes",
              }
              

              Note that the different couples Old names: New names, added, are not necessarily, listed in the same order than in the file itself. Luckily, it does not matter ;-))

              • Now, open the Replace dialog ( Ctrl + H )

              • SEARCH (?-s)("driverName":\x20)(".+?")(?=(?s:.+)^\2\h*:\h*(".+"))|(?s)\{[^{}]+\}\Z

              • REPLACE \1\3

              • Tick the Match case option, if necessary

              • Tick the Wrap around option

              • Select the Regular expression search mode

              • Click once on the Replace All button ( or several times on the Replace button )


              So, assuming the original JSON test, with the new object containing all the couples of names, at the very end :

              {
              "drivers": [
              {
              "driverName": "Jaime Baker",
              "carDesign": "21,fa7fed,000000,ffffff,fa7fed",
              "carNumber": "1",
              "suitDesign": "1,fa7fed,000000,ffffff",
              "helmetDesign": "1,fa7fed,000000,ffffff",
              "carPath": "mx5\mx52016",
              },
              {
              "driverName": "Steven Kourepenos",
              "carDesign": "0,111111,cccccc,ed1c24",
              "carNumber": "2",
              "suitDesign": "13,111111,cccccc,ed1c24",
              "helmetDesign": "63,111111,cccccc,ed1c24",
              "carPath": "mx5\mx52016",
              },
              {
              "driverName": "Jeff Rubin",
              "carDesign": "9,ffffff,1a4b9b,dff000",
              "carNumber": "3",
              "suitDesign": "23,ffffff,1a4b9b,dff000",
              "helmetDesign": "35,ffffff,1a4b9b,dff000",
              "carPath": "mx5\mx52016",
              },
              ...
              ...
              ...
              ...
              ...
              {
              "Steven Kourepenos": "Mark Skaife",
              "Jeff Rubin": "Russell Ingall",
              "Jaime Baker": "Craig Lowndes",
              }
              

              After clicking on the Replace All button, you should get the expected file :

              {
              "drivers": [
              {
              "driverName": "Craig Lowndes",
              "carDesign": "21,fa7fed,000000,ffffff,fa7fed",
              "carNumber": "1",
              "suitDesign": "1,fa7fed,000000,ffffff",
              "helmetDesign": "1,fa7fed,000000,ffffff",
              "carPath": "mx5\mx52016",
              },
              {
              "driverName": "Mark Skaife",
              "carDesign": "0,111111,cccccc,ed1c24",
              "carNumber": "2",
              "suitDesign": "13,111111,cccccc,ed1c24",
              "helmetDesign": "63,111111,cccccc,ed1c24",
              "carPath": "mx5\mx52016",
              },
              {
              "driverName": "Russell Ingall",
              "carDesign": "9,ffffff,1a4b9b,dff000",
              "carNumber": "3",
              "suitDesign": "23,ffffff,1a4b9b,dff000",
              "helmetDesign": "35,ffffff,1a4b9b,dff000",
              "carPath": "mx5\mx52016",
              },
              ...
              ...
              ...
              ...
              ...
              

              If this S/R does the job, I’ll tell you, next time, how this regular expression works… !

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              Copyright © 2014 NodeBB Forums | Contributors