Search and Replace
- From: Gavin Wraith <gavin@xxxxxxxxxxxxxxx>
- Date: Sun, 08 Jan 2012 13:52:30 GMT
Is there an easy way to apply a series of search and replace strings
to a piece of text, from a list or table?
Yes. Use StrongED and drag in a script like this, with the
replace table appropriately modified (presuming you have !lua
filerbooted).
#! lua
-- multiple search and replace
local replace = { -- edit this table
["seperate"] = "separate";
["supercede"] = "supersede";
["kernal"] = "kernel";
["old rubbish"] = "snappy phrase";
}
-- search for string in square brackets, replace with
-- string between equal sign and semicolon.
local transform = \(x,y)
for old,new in pairs(y) do
x = x:gsub(old,new)
end -- for
=> x
end -- function
local f = io.open(arg[1],"r")
local s = f:read "*all"
f:close()
io.write(transform(s,replace))
--
Gavin Wraith (gavin@xxxxxxxxxxxxxxx)
Home page: http://www.wra1th.plus.com/
.
- Prev by Date: Re: Search & Replace
- Next by Date: Re: Trying to get PackMan to install GCC
- Previous by thread: Search & Replace
- Next by thread: Remove Geminus
- Index(es):
Relevant Pages
|