Parsing text file in python
<p>So I am trying to python program that will extract the round trip time from a web server ping stored in a text file. So what I basically have is a text file with this:</p>

<pre><code>    PING e11699.b.akamaiedge.net (104.100.153.112) 56(84) bytes of data.
    64 bytes from a104-100-153-112.deploy.static.akamaitechnologies.com (104.100.153.112): icmp_seq=1 ttl=60 time=17.2ms
    64 bytes from a104-100-153-112.deploy.static.akamaitechnologies.com (104.100.153.112): icmp_seq=2 ttl=60 time=12.6ms
    64 bytes from a104-100-153-112.deploy.static.akamaitechnologies.com (104.100.153.112): icmp_seq=3 ttl=60 time=11.7ms
    ... (a bunch more ping responses here)
    --- e11699.b.akamaiedge.net ping statistics ---
    86400 packets transmitted, 86377 received, 0% packet loss, time 86532481ms
    rtt min/avg/max/mdev = 6.281/18.045/1854.971/28.152 ms, pipe 2
</code></pre>

<p>I am very new to python and need help being able to use regex commands to extract only the times between "time=" and "ms"and send it to another text file to look like:</p>

<pre><code>11.7
12.6
17.2
...
</code></pre>

<p>Any help would be greatly appreciated!</p>

<p>Since this seems to come from <a href="/questions/tagged/ping" class="post-tag" title="show questions tagged &#39;ping&#39;" rel="tag">ping</a> command, you could use <a href="/questions/tagged/grep" class="post-tag" title="show questions tagged &#39;grep&#39;" rel="tag">grep</a> like this :</p>

<pre><code>grep -oP 'ttl=\d+\s+time=\K[\d\.]+' file    
</code></pre>

<h3>Output :</h3>

<pre><code>17.2
12.6
11.7
</code></pre>

<h3>Note :</h3>

<p>It's very simple to search SO or/and google to use this regex in <em>pure python</em>.</p>

<h3>Hint :</h3>

<p><a href="http://stackoverflow.com/questions/13542950/support-of-k-in-regex">http://stackoverflow.com/questions/13542950/support-of-k-in-regex</a></p>

<h3>Bonus</h3>

<p>Because I still have to play with python :</p>

<p>(in a <a href="/questions/tagged/bash" class="post-tag" title="show questions tagged &#39;bash&#39;" rel="tag">bash</a> shell) :</p>

<pre><code>python2 &lt;&lt;&lt; $'import re\nf = open("/tmp/file", "r")\nfor textline in f.readlines():\n\tmatches = re.finditer("ttl=\d+\s+time=([\d\.]+)ms", textline)\n\tresults = [float(match.group(1).strip()) for match in matches if len(match.group(1).strip())]\n\tif results:\n\t\tprint results[0]\nf.close()\n'
</code></pre>

text-processing python