|
Well, Syd, here's my tyro level explanation. 'sed' stands for stream editor. It takes each record of a file (or the output of another command, like 'find') and runs it through some optional selection criteria (does the line match the regular expression?). If nothing is specified, as in these cases, every line is selected. The matching criteria are followed by a command, in this case, 's', which is 'substitute', I think. After 's' you put a string to be replace, followed by the replacement. A delimiter separates each of these. The standard delimiter is '/', but anything (except 'backslash and newline) can be used, esp. if you have a '/' in either the substitutor or the substitutee (I just made those up). I used a '%' when I had to. You put a backslash (what is called the escape character) in front of the first occurrence of the delimiter, then just use the delimiter thereafter (but locally to a particular evocation of sed). Finally, the output of each step is piped (using the '|' operator) to the next step. So, annotated: find --- the find command searches the directory recursively for files --- that match a specification (regular expressions work) /QSYS.LIB/VERN.LIB --- the point in the directory tree from which the search begins -name 'TEST*.MBR' --- the match spec - in this case, anything that ends with 'TEST', --- then any characters, then '.MBR' | --- the 'pipe' operator takes the output of one process and makes --- it input of another. We use this in DOS with dir | more to do a --- page at a time sed --- the stream editor command s\%/QSYS.LIB/%% --- the 's' (substitute) command --- because of the '/' in the search string, '%' is used as delimiter --- '/QSYS.LIB' is the search string --- because there is nothing between the last 2 delimiters, the --- search string is deleted (replace by nothing <g>) | --- the output of the previous process is made input to the next sed s/.LIB// --- no '/' in the search string, so normal delimiter used --- '.LIB' is deleted - I want to keep the following '/' for the lib/obj --- separator | --- again, output becomes input sed s\%.FILE/%\(% --- need different delimiter --- replace '.FILE/' with '(' - to enclose member name | --- as before sed /.MBR/s//\)/ --- can use default delimiter --- replace '.MBR' with closing ')' Now you see why Unix folk have obfuscation contests! Maybe it would've been clearer to use the \% for a delimiter throughout, even when not required by the content of the search and replace strings. You pays your money, you makes your choice. There are whole books written on sed alone. The documentation in QShell, and in Unix man pages, is sketchy. It also assumes some knowledge of regular expressions, which are tremendously powerful and flexible and confusing (MS uses something like these in Word, for wildcard searches, but, of course, it is not standard.) Refer, again, to the links below for QShell info. HTH Vern At 04:04 PM 11/8/02 +0000, you wrote:
Excellent stuff Vern. This could be very usefull. Unfortunately I don't understand the UNIX syntax, or what sed does. Any chance of an explanation? Syd Nicholson Vern Hamberg wrote:
-snip-
There's a PDF of the QShell Referenece, <http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzahz/rzahz.pdf> is the V5R2 version, <http://publib.boulder.ibm.com/iseries/v5r1/ic2924/info/rzahz/rzahz.pdf> the V5R1 version. Regards Vern
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.