Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Combining bits that are the same

 [1/4] from: andrew::martin::colenso::school::nz at: 24-Jul-2003 9:59


Hi! Have a look at these three scripts: ========================== ========================== ====================== ===== ; Mass replace text content in files: Mass_Replace: func [Folder [file!] Target [string!] Replacement [string!]] [ map recursive-read Folder func [File [file!]] [ if %.dmt = extension? File [ probe File write Folder/:File replace/all read Folder/:File Target Replacement ] ] ] Mass_Replace %"/N/CM/documents/2003 T3/" "SEPTEMBER 2002" "September 2003" ========================== ========================== ====================== ===== ; Mass delete of files matching pattern: foreach File recursive-read Folder: %"/C/Rebol/" [ if any [ %Thumbs.db = last Folder_File: split-path File %.bak = extension? last Folder_File ] [ delete Folder/:File probe Folder/:File ] ] ========================== ========================== ====================== ===== ; Mass renaming of files matching pattern: foreach File read Folder: %"/N/CM/documents/2003 T3/" [ if all [ %.dmt = extension? File found? Index: find File Target: "T3 " 1 = index? Index ] [ probe File attempt [rename Folder/:File copy find/tail File Target] ] ] ========================== ========================== ====================== ===== Notice how there are similarities? I'd like to express that similarity in one function with a kind of "programmable" action. I get the feeling that the Unix "GREP" command could be similar to what I want, but I've got no familiarity with Unix or the GREP command. Anyone know if GREP would a good model or goal to work towards with Rebol? Thanks! Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [2/4] from: greggirwin:mindspring at: 24-Jul-2003 8:27


Hi Andrew, AM> Notice how there are similarities? I'd like to express that similarity AM> in one function with a kind of "programmable" action. I get the feeling AM> that the Unix "GREP" command could be similar to what I want, but I've AM> got no familiarity with Unix or the GREP command. Anyone know if GREP AM> would a good model or goal to work towards with Rebol? Both AWK and Grep can operate on sets of files. Grep is used for finding data in files; AWK lets you execute actions and do actual programming type stuff. What they do is iterate over files for you, which is the common bit that saves you time and effort. AWK also splits each line into fields automatically so you don't have to parse them yourself. Sed is used to make changes to files, while Grep isn't (though some implemenations may support it). I've got a simple AWK-like thing, and a basic GREP-ish thing on top of that, but only notes on a SED-like tool. I think they are very useful models, but can be made much friendlier than their namesakes. -- Gregg

 [3/4] from: AJMartin:orcon at: 25-Jul-2003 5:20


Gregg wrote:
> I've got a simple AWK-like thing, and a basic GREP-ish thing on top of
that, but only notes on a SED-like tool. I think they are very useful models, but can be made much friendlier than their namesakes. Thanks, Gregg! Can we see your AWK thing, please? :) Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/

 [4/4] from: greggirwin:mindspring at: 25-Jul-2003 10:06


Hi Andrew, AJM> Thanks, Gregg! Can we see your AWK thing, please? :) It's on IOS developer. I asked at one point if people were interested and only got a couple responses, so I never have taken the time to clean it up and put it in the library. Holler if you want me to mail it to you. -- Gregg