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

Re: [StrongED] Multiple changes to multiple files

In message <82af4b1653.iyojohn@xxxxxxxxxxxxxxxxxxxxx> you wrote:

> I would like to apply the same set of changes to a directory of about 
> 50 files.
> The changes are:
> 1. Wrap a pair of <h1> tags around the first line of the file.
> 2. Insert some lines of text before the first line of the file
> 3. Wrap a pair of <h2> tags around all lines beginning with a #.
> 4. Add some lines of text to the end of the file.
> The files can all be loaded using ctrl drag-drop
> 1. and 3.   can be done using Search and Replace
> I would appreciate some help on how to do 2. and 4.

I am sure StrongED can do this with the right commands, but this
sort of thing is very easy with StrongED scripting. Awk or Lua
come to mind as the right tools for such a job. A RiscLua script
could look like this:

#! lua
local wrapfmt = "<%s>%s</%s>"
local wrap = \ (s, tag) => wrapfmt:format (tag, s, tag) end
local line_no = 1
print (start_stuff) 
for line in io.lines (arg[1]) do
 if line_no == 1 then print (wrap (line, "h1")) 
  if line:sub(1,1) == "#" then print (wrap (line, "h2")) 
  else print (line) end -- if
 end -- if
 line_no = line_no + 1
end -- for
print (end_stuff)

Fill in your own bits for start_stuff and end_stuff.
Gavin Wraith (gavin@xxxxxxxxxxxxxxx)
Home page: http://www.wra1th.plus.com/

To unsubscribe send a mail to StrongED+unsubscribe@xxxxxxxxxxxxxx