[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: conditional replace
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Mon, 17 Sep 2007 21:31:15 -0600
On 9/17/07, Thomas A. Schmitz <thomas.schmitz@uni-bonn.de> wrote:
> But how do I write the rest of the file back? Sorry if this is a
> nobrainer, but I'm certainly not a programmer.
It would probably be better to just let everything be done via stdin
and stdout, using pipes:
========
#!/usr/local/bin/lua
file = io.stdin:read("*all");
file = string.gsub(file, "localgreek(%b{})", function(lines)
return "localgreek"..string.gsub(lines, 'a', 'b');
end);
io.stdout:write(file);
=======
You will probably want to have the "return "localgreek" ..." part of
the code just call a function which iterates over your table of
substitutions for each capture. Notice that you need the "localgreek"
part concatenated otherwise you lose it.
HTH,
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant