I have a file test.xml
(shown below).
This grep works:
grep '<appointment-id internal:ref=1.2.3/>' test.xml
Output is:
<appointment-id internal:ref=1.2.3/>
But this fails:
grep "$(grep '<appointment-id internal:ref=1.2.3/>' test.xml)" test.xml
Output is:
grep: invalid character range
Contents of test.xml
:
<note>
<to>Jim</to>
<from>John</from>
<heading>Reminder</heading>
<body>Some text</body>
<appointment-id internal:ref=1.2.3/>
</note>
I have put both grep
commands (the simple one and the nested one)
into a script with set -x
.
Here is an exact copy & paste of that script:
set -x
grep '<appointment-id internal:ref=1.2.3/>' test.xml
grep "$(grep '<appointment-id internal:ref=1.2.3/>' test.xml)" test.xml
exit 0
and here is its output:
++ grep '<appointment-id internal:ref=1.2.3/>' test.xml
<appointment-id internal:ref=1.2.3/>
+++ grep '<appointment-id internal:ref=1.2.3/>' test.xml
++ grep ' <appointment-id internal:ref=1.2.3/>' test.xml
grep: invalid character range
++ exit 0
GREP_COLOR=auto
,grep
should only produce colorized output when writing directly to the terminal. This may be better for you, possibly. – Kusalananda Jun 07 '18 at 21:33