Is there a better way?
<p>I have file say <code>abc.txt</code> with below format:</p>

<pre><code>+ : @group2 : ALL  
+ : @grp_xvz : ALL  
+ : @group_abc_app: ALL  
+ : @group_1_abc : ALL  
+ : @group_2_xyz : ALL  
+ : @group_3_def@@nmo_hosts : ALL
</code></pre>

<p>I need to grep for specific entries and check if file size of abc.txt > 220  </p>

<pre><code>+ : @group_2_xyz : ALL   or 
+ : @group_3_def@@nmo_hosts : ALL   
and  filesize of abc.txt &gt; 220  
</code></pre>

<p>In bash I can do like this</p>

<pre><code>if grep --quiet "+[[:blank:]]:[[:blank:]]@group_2_xyz[[:blank:]]*:[[:blank:]]ALL" abc.txt   
||  
 grep --quiet +[[:blank:]]:[[:blank:]]@group_3_def[@A-Za-z0-9_][[:blank:]]:[[:blank:]] abc.txt   
and                                                   
[ du -sb abc.txt | awk '{print $1}' -gt 220 ]; then  

..do..something
</code></pre>

<p>How to do same in python? I was trying to use "re.findall' but not sure if I can use multiple conditions there ? or if someone can suggest best way?</p>

<pre><code>re.findall(r'+\s*:\s*@group_2_xyz\s*:\s*ALL', open('abc.txt,'r').read())
</code></pre>

<p>Thanks in advance.</p>

<p>Try this:</p>

<pre><code>import os, re

match = re.search(
    r'^\+ *: *(@group_2_xyz|@group_3_def@@nmo_hosts) *: *ALL$',
    open('abc.txt').read(), re.M
    )

print(os.stat('abc.txt').st_size &gt; 220, match is not None)
</code></pre>

python