Using 'grep x' is not always identical to using 'match' with 'find:x'
The following two commands should produce the same result. The first finds nothing (which is incorrect). The second produces the expected output.
$ rosie --rpl 'hwo = find:{"Hardware Overview:" find:>"\nMemory"}' match -w -o subs hwo /tmp/info
$ rosie --rpl 'hwo = {"Hardware Overview:" find:>"\nMemory"}' grep -w -o subs hwo /tmp/info
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro12,1
Processor Name: Dual-Core Intel Core i5
Processor Speed: 2.9 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 3 MB
Hyper-Threading Technology: Enabled
Memory: 8 GB
System Firmware Version: 425.0.0.0.0
SMC Version (system): 2.28f7
$
The bug is likely related to the error (below) in expand
which shows that the newline sequence \n
in the literal string in the pattern is interpreted as a literal backslash followed by n
.
$ rosie expand '{"Hardware Overview:" find:>{"\nMemory"}}'
Input: {"Hardware Overview:" find:>{"\nMemory"}}
Parsed as an RPL expression: {"Hardware Overview:" find:{>{"\\nMemory"}}}
Tokenized expression by default: {"Hardware Overview:" find:{>{"\\nMemory"}}}
Macro expands to: {"Hardware Overview:"
grammar
alias <search> = {!>"\\nMemory" .}*
<anonymous> = {>"\\nMemory"}
in
alias find = {<search> <anonymous>}
end
}
$