Note that there are some explanatory texts on larger screens.

plurals
  1. POBash script grep for pattern in variable of text
    primarykey
    data
    text
    <p>I have a variable which contains text; I can echo it to stdout so I think the variable is fine. My problem is trying to grep for a pattern in that variable of text. Here is what I am trying:</p> <pre><code>ERR_COUNT=`echo $VAR_WITH_TEXT | grep "ERROR total: (\d+)"` </code></pre> <p>When I echo $ERR_COUNT the variable appears to be empty, so I must be doing something wrong. </p> <p>How to do this properly? Thanks.</p> <p>EDIT - Just wanted to mention that testing that pattern on the example text I have in the variable does give me something (I tested with: <a href="http://rubular.com" rel="nofollow">http://rubular.com</a>)</p> <p>However the regex could still be wrong.</p> <p>EDIT2 - Not getting any results yet, so here's the string I'm working with:</p> <p><code>ALERT line125: Alert: Cannot locate any description for 'asdf' in the qwer.xml hierarchy. (due to (?i-xsm:\balert?\b) ALERT in ../hgfd.controls) ALERT line126: Alert: Cannot locate any description for 'zxcv' in the qwer.xml hierarchy. (due to (?i-xsm:\balert?\b) ALERT in ../dfhg.controls) ALERT line127: Alert: Cannot locate any description for 'rtyu' in the qwer.xml hierarchy. (due to (?i-xsm:\balert?\b) ALERT in ../kjgh.controls) [1] 22280 IGNORE total: 0 WARN total: 0 ALERT total: 3 ERROR total: 23 [1] + Done /tool/pandora/bin/gvim -u NONE -U NONE -nRN -c runtime! plugin/**/*.vim -bg ...</code></p> <p>That's the string, so hopefully there should be no ambiguity anymore... I want to extract the number "23" (after "ERROR total: ") into a variable and I'm having a hard time haha. </p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload