:GREP_PROCESS, GREP_PROCESS
Use GREP_PROCESS to filter lines in a text container. You can use this scripting element with regular expressions and process handles, and also select specific columns and work only within them.
Note: The terms Data Sequences and Text Containers are used interchangeably.
This scripting element can be used as both, a script statement and a script function:
-
When used as a script statement, it modifies the text container of the input handle and provides the result in that text container. This is useful for stacking commands to modify text containers, thus avoiding reallocating new process handles.
-
When used as a script function, the text container of the process handle is provided read-only, and the result is provided in a new text container as a return value of the function.
Syntax
When used as a script statement:
:GREP_PROCESS Handle[, Regex[, Column[, Flags]]]
When used as a script function:
GREP_PROCESS (Handle[, Regex[, Column[, Flags]]])
Parameters
| Parameter | Description | Format |
|---|---|---|
| Handle | Process handle of a text container. | Script literal or script variable |
| Regex
(Optional) |
Regular expression to be used. Regular expressions follow the Boost C++ Libraries syntax. For more information, see the official Boost C++ Libraries documentation. |
n.a. |
| Column
(Optional) |
The index indicates which column to search, beginning with 1. Use 0 to search the entire line. If the text container (data sequence) was loaded with columns defined, you can select a specific column and use this script element to work within that column. Make sure you know which column delimiter was used when the text container was loaded. If needed, you can define the delimiter using the 'd' flag. Note: When you specify a column for grepping, the grepped result still contains the full lines. |
Script literal, script variable, or number without quotation marks |
| Flags
(Optional) |
Use flags to modify the operation. The available flags are:
Flags can be combined and provided in any order. For example, if you combine flag i with flag n, you can do so using "in" or "ni", or the script variable &FLAG#. An exception is the flag "d", which specifies a multi-character sequence as a delimiter used to separate columns in a text. |
n.a. |
Examples
The following example greps and modifies the content of a file through a series of operations:
!* Load text container from a file
:SET &HND_TEXT# = PREP_PROCESS_FILE(AR_MAIN_JWX6_VFRKARWIN01_01, "C:\Temp\ContentFile.txt" ,,, 'UC_LOGIN=AR.LOGIN.OK')
!* 1.) Number all lines of the text
:SET &HND_NUMBERED_LINES# = GREP_PROCESS(&HND_TEXT#, "" ,, "l")
!* Output lines
:SET &NUMBER_LINES# = GET_PROCESS_INFO(&HND_NUMBERED_LINES#, ROWS)
:PRINT &NUMBER_LINES# LINES
:PROCESS &HND_NUMBERED_LINES#
:SET &LINE# = GET_PROCESS_LINE(&HND_NUMBERED_LINES#)
:PRINT &LINE#
:ENDPROCESS
!* 2.) Get rid of empty lines
:GREP_PROCESS &HND_TEXT#, "^[ ]*$",, "v"
!* Output lines
:SET &NUMBER_LINES# = GET_PROCESS_INFO(&HND_TEXT#, ROWS)
:PRINT &NUMBER_LINES# LINES
:PROCESS &HND_TEXT#
:SET &LINE# = GET_PROCESS_LINE(&HND_TEXT#)
:PRINT &LINE#
:ENDPROCESS
!* 3.) Get only lines which start with a word with uppercase letters and has at least two letters
:GREP_PROCESS &HND_TEXT#, "^[[:upper:]][[:alpha:]]"
!* Output lines
:SET &NUMBER_LINES# = GET_PROCESS_INFO(&HND_TEXT#, ROWS)
:PRINT &NUMBER_LINES# LINES
:PROCESS &HND_TEXT#
:SET &LINE# = GET_PROCESS_LINE(&HND_TEXT#)
:PRINT &LINE#
:ENDPROCESS
!* 4.) Remove all words which start with a lower case letter
:MODIFY_PROCESS &HND_TEXT#, " [[:lower:]][[:alpha:]]*", "" ,, "g"
!* Output lines
:SET &NUMBER_LINES# = GET_PROCESS_INFO(&HND_TEXT#, ROWS)
:PRINT &NUMBER_LINES# LINES
:PROCESS &HND_TEXT#
:SET &LINE# = GET_PROCESS_LINE(&HND_TEXT#)
:PRINT &LINE#
:ENDPROCESS
!* 5.) Remove all characters which are no letters except spaces
:MODIFY_PROCESS &HND_TEXT#, "[[:punct:]]", "" ,, "g"
!* Output lines
:SET &NUMBER_LINES# = GET_PROCESS_INFO(&HND_TEXT#, ROWS)
:PRINT &NUMBER_LINES# LINES
:PROCESS &HND_TEXT#
:SET &LINE# = GET_PROCESS_LINE(&HND_TEXT#)
:PRINT &LINE#
:ENDPROCESS
!* 6.) Take that text container and exchange the first with the last word in each line
:MODIFY_PROCESS &HND_TEXT#, "^([[:alpha:]]+)((.*)?)([[:alpha:]]+)$", "$4$2$1"
!* Output lines
:SET &NUMBER_LINES# = GET_PROCESS_INFO(&HND_TEXT#, ROWS)
:PRINT &NUMBER_LINES# LINES
:PROCESS &HND_TEXT#
:SET &LINE# = GET_PROCESS_LINE(&HND_TEXT#)
:PRINT &LINE#
:ENDPROCESS
See also: