This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Find and Replace script
#1
Hi

I am trying to create a script that can find a certain text inside the object name and replace it with another string. This is so I do not need to do this manually every time there is a large change.

For normal GA I would just use the update from ESF-file solution, but I often have a lot of virtual addresses as well, and they also must be updated.

I am able to find the adresses to update, and to generate the new name, but for some reason I am not able to update the name of the object. If anyone has an idea of why, please give me a hint.

The code I have entered is as follows;
Code:
finn = '360.001'
replace = '360.002'
kriterie = '08-0'



liste = db:getall('SELECT name FROM objects WHERE name LIKE "%'.. kriterie .. '%" AND name LIKE "%'.. finn .. '%"')

--
for _, name in ipairs(liste) do
  navn = name.name
  --log(navn)
  if string.find(navn, finn, 1, true) == nil then
    log('fikk nil')
  else
    log('fant strengen')
    newName = string.gsub(navn, finn, replace)
    log(navn, newName)
    ga = grp.find(navn)
    --db:update('objects', { name = newName }, { id = id })
    --log(ga)
    address = grp.create({
        address = ga.address,
        name = newName,
      })
  end
 
end
log('Ferdig')

script.disable(_SCRIPTNAME)

I am sorry for Norwegian names in variables, but that makes it more easy to prevent using a word that has a LUA-meaning....
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Messages In This Thread
Find and Replace script - by Trond Hoyem - 10.01.2020, 10:52
RE: Find and Replace script - by admin - 10.01.2020, 12:48
RE: Find and Replace script - by Trond Hoyem - 10.01.2020, 13:06
RE: Find and Replace script - by admin - 10.01.2020, 13:35
RE: Find and Replace script - by Trond Hoyem - 10.01.2020, 13:53
RE: Find and Replace script - by admin - 10.01.2020, 14:06
RE: Find and Replace script - by Trond Hoyem - 10.01.2020, 14:10

Forum Jump: