I am attempting to pipe input between two range patterns of a file to a
process, then replace that text in the range pattern to the output of
the called process.
awk does not exactly work because the output of the process will attach
to the awk's stdout and output its data after the awk output. Here's
what I want to do (let's just assume it is `cksum' as the external
process):
$cat foo
blah
blah2
%%{
cksum data area
data area line 2
%%}
blah5
...
blah799
the output should be
blah
blah2
3677025507 41
blah5
...
in awk, I could do the following:
/^%%{/,/^%%}/ {
if ( ! (( $0 ~ /^%%{/ ) || ( $0 ~ /^%%}/ )) ) print |"cksum"
however, the cksum output takes in all disparate matching data lines andQuote:}
outputs the data AFTER the awk output of the other lines. (note that a
few flags must be set to make awk NOT output the range pattern lines)
I even attempted modifying GNU sed code and adding a function that would
do what vi's `!' does, but attaching and syncing stdin/out of another
process into stdin/out of the current process is not trivial and it was
core dumping all over the place.
I could use an ex script:
ex - foo <<EOF
/%%{/,/%%}/!cksum
w !cat
EOF
but this writes the ex output out in the stream.
What does one do? None of these work.
--
J. S. Jensen
http://www.paramin.com