[ < < < Home ]
[ < < Reference Start ]
[ < Reference Contents ]
[ < Previous=PDGREPPE Replace Symbols ]
[ Next=PDGREPPE Replace Controls > ]
Symbols like & % - + ? are used to replace areas of a match with assorted values. When a match is found it encompasses two main areas, either the entire matched area, represented by the "&" symbol, or various subsections of the match area that have been located with the Marked Group operators "(" and ")" in the search pattern. So if a search pattern is "(bananas) or (apples)" and the replacement pattern is "%1 or %0" and a match is found, then the replacement becomes "apples or bananas" the REVERSE of what is found : "bananas or apples". This is simple swapping at work! Or another example, if the search pattern is "again" and the replacement pattern is "&\, and &\, and &" and a match is found, then the replacement becomes "again, and again, and again". Use of these symbols is a convenient way to reduce the number of characters entered as a replacement, or to rearrange them in some way with LESS typing or literal representation. SPECIAL SYMBOL & insert all of data match pdgreppe "TextTools" -kekikwkr"& & &" file_id.diz ..."& & &" inserts "TextTools" in a copy of file_id.diz 3 times with spaces. SPECIAL SYMBOL FORM %<n> insert <n>th Marked Group of data match pdgreppe "(Intelligence) Services" -kekikwkr"& %0" file_id.diz Here: & %0 inserts entire contents of match: "&" or "Intelligence Services" a space: " " then "%0" contents of Marked Group 0 or "Intelligence" to become Intelligence Services Intelligence Likewise: %<VName> insert Marked Group of data match identified by <VName> pdgreppe "(Intelligence)=intel Services" -kekikwkr"& %intel" file_id.diz So: & %intel inserts entire contents of match: "&" or "Intelligence Services" a space " " then "%intel" to repeat the data in the Marked Group identified by "intel" (Intelligence) to become Intelligence Services Intelligence SPECIAL SYMBOL FORM +<n>{<pat>} insert pattern <pat> if Passed <n>th Marked Group This is an UNCONDITIONAL replacement function that replaces "<pat>" if the <n>th or <named> marked (group) is ANY OR ALL of the match area. pdgreppe "Re(lease)" -kekikwkr"+0{Version}" file_id.diz ..."Re(lease)" is found and "+0{Version}" has changed "Release" to "Version" because Marked Group 0 (lease) was found. The change is made WITHOUT REGARD to the difference between Marked Group 0's width and the entire match width of "Re(lease)" The other variety, +<VName>{<pat>} insert pattern <pat> if Passed Marked Group identified by <VName> works likewise: pdgreppe "Re(lease)=lea" -kekikwkr"+lea{Version}" file_id.diz "Re(lease)=lea" is found and "+lea{Version}" has changed "Release" to "Version" because the Marked Group is named or tagged by "=lea" (lease) was found. Again, the change is made WITHOUT REGARD to the difference between Marked Group "lea" width and the entire match width of "Re(lease)" SPECIAL SYMBOL FORM ?<n>{<pat>} insert pattern <pat> if Passed <n>th Marked Group and Marked Group width is ALL of match This is a conditional replacement function that allows a replacement of "<pat>" to be made only if the <n>th marked (group) is all of the match area. pdgreppe "(Release)" -kekikwkr"?0{Version}" file_id.diz ..."(Release)" is found and "?0{Version}" has changed "Release" to "Version" because Marked Group 0 (Release) was found and is ALL of match area. pdgreppe "Re(lease)" -kekikwkr"?0{Version}" file_id.diz However with this pattern "Re(lease)" is found and "?0{Version}" could DELETE "Release" rather than change it to "Version" because Marked Group 0 (lease) was found and is NOT ALL of match area. So the replace pattern is empty "?0{Version}" and a delete is done instead. Other variety: ?<VName>{<pat>} insert pattern <pat> if Passed Marked Group identified by <VName> and Marked Group width is ALL of match pdgreppe "(Release)=rel" -kekikwkr"?rel{Version}" file_id.diz ..."(Release)=rel" is found and "?rel{Version}" has changed "Release" to "Version" because Marked Group identified by (Release)=rel was found and is ALL of match area. BEWARE A mistake can occur when a SINGLE MINUS MARK starts a replace pattern exactly after option -kr: It is interpreted as meaning "turn off" option -kr. To overcome this either start the pattern with a double quote or whitespace between -kr and the pattern. eg -kr"-meToo{XX}" -kr -9{XX} SPECIAL SYMBOL FORM -<n>{<pat>} insert pattern <pat> if NOT Passed <n>th Marked Group -<VName>{<pat>} insert pattern <pat> if NOT Passed Marked Group identified by <VName> These are like the +<n> and ?<n> forms just shown but replace with the substitution pattern {<pat>} if the (Marked Group) search pattern segment identified by <n> or <VName> FAILED. It is good for making a selective insert if something was NOT found in a search pattern. eg pdgreppe "pattern(s)?" -kekikwkr":U&-0{isation}" file_id.diz finds lines in FILE_ID.DIZ with PDGREPPE and FGREPPE and CAPITALISES with the ":U" all-to-upper-case function of the match to Search term "pattern(s)?". And for the line with FGREPPE where "pattern" is WITHOUT an "s" at its end, "(s)" of "(s)?" DOES NOT MATCH because there is NO "s" after "pattern", PDGREPPE performs an additional paste of "isation" that also becomes upper-case to become PATTERNISATION Summary of Selective Marked Group Replace functions: The +<n>, ?<n> and -<n> {<pat>} Edit Replace functions offer a way to change any of a number of different edit patterns to be completely different by substitution. pdgreppe "(Search)|(by)" -kekikwkr"?0{FIND}?1{WITH}" file_id.diz ...the replacement pattern "?0{Find}?1{with}" changes the match of strings "Search" or "by" in search pattern (Search)|(by) to become entirely different strings "Find" or "with" if pattern match is made in Marked Groups 0 OR 1. pdgreppe "(<\l+>)|(<\u+>)" -kekwkr"?0{Peas}?1{BEANS}" file_id.diz ...changes any lower-case word "(<\l+>)" or upper-case word "(<\u+>)" to become entirely different strings "Peas" or "BEANS" if a match is made in Marked Groups 0 or 1. Great Stuff! You can edit between plenty different patterns in one swoop provided You keep track of the Marked Group alignments or variable names. All <n> numbers or <VName> names given for Marked Groups in Edit Patterns BY DEFAULT MUST correspond to the Marked Groups in the upper level MAIN User Pattern, NOT Marked Groups in any @Definition used by the upper level user pattern or another pattern @Definition. However, with editing option "-kg", names given for Marked Groups can be accessed as GLOBAL names that reference UNIQUE Marked Groups. Option "-jg" should also be used with this option to make a total search pattern only contains UNIQUE Marked Group names. Be careful with replace patterns containing &, %<n> and [+?-]<n>{<dat>} because they can also DELETE data if the original match area had zero width (& and %<n>) or if the replacement pattern data has zero width ([+?-]<n>{<empty>}). See PDGREPPE Options "-jg" and "-kg".
[ < < < Home ]
[ < < Reference Start ]
[ < Reference Contents ]
[ < Previous=PDGREPPE Replace Symbols ]
[ Next=PDGREPPE Replace Controls > ]
© Intelligence Services 1987 - 2008
GPO Box 9, ADELAIDE SA 5001, AUSTRALIA
EMAIL : intlsvs@gmail.com