lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Apr 18, 2011 at 11:19:07AM +0200, Gilles Ganault wrote:
> Hello
> 
> 	I need to write a script that checks for unused dynamic libraries,
> so I can remove them and save space on an appliance.
> 
> Using scanelf, the input file is a list of executables and the dynamic
> libraries it need:
> ============
> exec1 lib1,lib2,lib3
> exec2 lib1
> etc.
> ============
> 
> Here's what I have to far, but I can't get split() to work to extract
> the list of libraries from each line in the file:

split() is not in Lua, because it is so easy to roll your own with Lua 
patterns.  

---------------------------
-- define the necessary patterns
exec_libs_pat = "%s*(%S+)%s*(%S+)"  -- first two space-separated fields
libs_pat = ",?([^,]+)"              -- pattern for comma-separated fields

execs = io.open("execs.txt","r")
for line in execs:lines() do
    exec, libs = string.match(line,exec_libs_pat)
    for lib in string.gmatch(libs,libs_pat) do print(lib) end
    end
----------------------------

Dirk