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

[StrongED] searching for last word in a field



> I am trying to process a friend's list of postal addresses
> What I want to do is copy the surname in each record to a new column that
> I can then use to sort abfaletically:

This Lua script should do the trick:

#! lua
local blank = "^[%s\t]*$"
local surname = "([^%s\t]+)\t"
local fmt = "%s\t%s"
local ready
for line in io.lines (arg[1]) do
 if line:match (blank)then ready = true; print (line)
 else
  if ready then
    local name = line:match (surname)
    if name then print (fmt:format (name, line))
    else print (line)
    end -- if
    ready = nil
  else
   print (line)
  end -- if
 end -- if
end -- for

--
Gavin Wraith (gavin@xxxxxxxxxxxxxxx)
Home page: http://www.wra1th.plus.com/

-- 
To unsubscribe send a mail to StrongED+unsubscribe@xxxxxxxxxxx
List archives and instructions at
http://stronged.torrens.org/index.html