diff options
author | Mike Mason <ms13sp@gmail.com> | 2007-11-22 16:22:47 +0000 |
---|---|---|
committer | Mike Mason <ms13sp@gmail.com> | 2007-11-22 16:22:47 +0000 |
commit | 38270a89a9a044005f949f5b73bf55c54117dbdd (patch) | |
tree | a7c839bed6d13189637b063a84523af14e98e768 /lib | |
parent | 865540bb0e294d07b3d532bec4066e463cab5a1f (diff) | |
download | acf-core-38270a89a9a044005f949f5b73bf55c54117dbdd.tar.bz2 acf-core-38270a89a9a044005f949f5b73bf55c54117dbdd.tar.xz |
Added a search replace function for files
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@356 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.lua | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -46,6 +46,7 @@ function read_file_as_array ( path ) local f = {} for line in file:lines() do table.insert ( f , line ) + --sometimes you will see it like f[#f+1] = line end file:close() return f @@ -72,6 +73,18 @@ end -- returns a table to iterate over without the blank or commented lines return lines end + +--will search and replace through the whole of the file and return a table + +function search_replace (path , find, replace) +local f = fs.read_file_as_array(path) +local lines = {} +for a,b in ipairs(f) do +local c = string.gsub(b, find, replace) +lines[#lines + 1] = c end +return lines +end + -- write a string to a file !! MM-will replace file contents @@ -83,7 +96,7 @@ function write_file ( path, str ) end end --- this could do more than a line +-- this could do more than a line. This will append -- fs.write_line_file ("filename", "Line1 \nLines2 \nLines3") function write_line_file ( path, str ) |