<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[moeglichst elegant logfile parsen]]></title><description><![CDATA[<p>Hallo,<br />
ich habe vor ein ASCII tcpdump logfile einzulesen, wobei eine Zeile folgendes Format hat:<br />
<code>18:12:27.808667 14744803536us tsft short preamble 54.0 Mb/s 2437 MHz (0x0480) -25dB signal -96dB noise antenna 1 71dB signal 44us 00:14:6c:0d:60:c2 (oui Unknown) &gt; 00:18:4d:8a:b4:f6 (oui Unknown) Null Information, send seq 0, rcv seq 0, Flags [Command], length 1480</code></p>
<p>Zeilenweise einlesen tue ich das file mit:</p>
<pre><code class="language-cpp">std::string line;
std::ifstream infile(filename, std::ios_base::in);
while (getline(infile, line, '\n')) {
   // Zeile bearbeiten
}
</code></pre>
<p>Nun habe ich bisher immer jede Zeile in std::strings tokens geteilt (Leerzeichen) und diese fuer weitere Verarbeitung in einen std::vector<a href="std::string" rel="nofollow">std::string</a> gepusht. Allerdings brauche ich von der Zeile oben nur <code>54.0 00:14:6c:0d:60:c2 00:18:4d:8a:b4:f6 1480</code></p>
<p>Mein erster Gedanke war irgendwie scanf nachzubasteln</p>
<pre><code class="language-cpp">std::string input = &quot;foo bar 10 20 hello 30&quot;
int a,b,c;
std::string garbage;
stringstream foo;
foo &lt;&lt; input;
input &gt;&gt; garbage &gt;&gt; garbage &gt;&gt; a &gt;&gt; b &gt;&gt; garbage &gt;&gt; c;
</code></pre>
<p>finde das aber nicht sehr effizient.</p>
<p>Also meine Frage ist, wie ich aus der Zeile am elegantesten die Werte extrahiere die mich interessieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/269463/moeglichst-elegant-logfile-parsen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 09:43:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/269463.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 25 Jun 2010 11:36:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to moeglichst elegant logfile parsen on Fri, 25 Jun 2010 11:36:58 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe vor ein ASCII tcpdump logfile einzulesen, wobei eine Zeile folgendes Format hat:<br />
<code>18:12:27.808667 14744803536us tsft short preamble 54.0 Mb/s 2437 MHz (0x0480) -25dB signal -96dB noise antenna 1 71dB signal 44us 00:14:6c:0d:60:c2 (oui Unknown) &gt; 00:18:4d:8a:b4:f6 (oui Unknown) Null Information, send seq 0, rcv seq 0, Flags [Command], length 1480</code></p>
<p>Zeilenweise einlesen tue ich das file mit:</p>
<pre><code class="language-cpp">std::string line;
std::ifstream infile(filename, std::ios_base::in);
while (getline(infile, line, '\n')) {
   // Zeile bearbeiten
}
</code></pre>
<p>Nun habe ich bisher immer jede Zeile in std::strings tokens geteilt (Leerzeichen) und diese fuer weitere Verarbeitung in einen std::vector<a href="std::string" rel="nofollow">std::string</a> gepusht. Allerdings brauche ich von der Zeile oben nur <code>54.0 00:14:6c:0d:60:c2 00:18:4d:8a:b4:f6 1480</code></p>
<p>Mein erster Gedanke war irgendwie scanf nachzubasteln</p>
<pre><code class="language-cpp">std::string input = &quot;foo bar 10 20 hello 30&quot;
int a,b,c;
std::string garbage;
stringstream foo;
foo &lt;&lt; input;
input &gt;&gt; garbage &gt;&gt; garbage &gt;&gt; a &gt;&gt; b &gt;&gt; garbage &gt;&gt; c;
</code></pre>
<p>finde das aber nicht sehr effizient.</p>
<p>Also meine Frage ist, wie ich aus der Zeile am elegantesten die Werte extrahiere die mich interessieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917226</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917226</guid><dc:creator><![CDATA[alpha21]]></dc:creator><pubDate>Fri, 25 Jun 2010 11:36:58 GMT</pubDate></item><item><title><![CDATA[Reply to moeglichst elegant logfile parsen on Fri, 25 Jun 2010 12:04:13 GMT]]></title><description><![CDATA[<p>alpha21 schrieb:</p>
<blockquote>
<p>Hallo,<br />
ich habe vor ein ASCII tcpdump logfile einzulesen, wobei eine Zeile folgendes Format hat:<br />
<code>18:12:27.808667 14744803536us tsft short preamble 54.0 Mb/s 2437 MHz (0x0480) -25dB signal -96dB noise antenna 1 71dB signal 44us 00:14:6c:0d:60:c2 (oui Unknown) &gt; 00:18:4d:8a:b4:f6 (oui Unknown) Null Information, send seq 0, rcv seq 0, Flags [Command], length 1480</code></p>
</blockquote>
<p>Wenn die zeile gleich bleibt, leg ne while drüber und schmeiss die unnötigen teile wieder aus dem vector</p>
<pre><code class="language-cpp">string tmpstr = &quot;aa bb cc&quot;;
	istringstream iss(tmpstr);

	vector&lt;string&gt; parts;
	copy(istream_iterator&lt;string&gt;(iss),istream_iterator&lt;string&gt;(),back_inserter&lt;vector&lt;string&gt;&gt;(parts));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1917239</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917239</guid><dc:creator><![CDATA[darkfate]]></dc:creator><pubDate>Fri, 25 Jun 2010 12:04:13 GMT</pubDate></item><item><title><![CDATA[Reply to moeglichst elegant logfile parsen on Sat, 26 Jun 2010 12:55:39 GMT]]></title><description><![CDATA[<p>eine idee waere vielleicht:</p>
<pre><code class="language-cpp">class skip_strings
{
   public:
      skip_strings(int val = 1) : value(val) { }

      std::istream&amp; operator()(std::istream &amp;in)
      {
         if(value == 0)
            return in;

         std::streambuf *buf = in.rdbuf();   
         char c = buf-&gt;sgetc(); 

         do
         {  
            while(std::isspace(c)) c = buf-&gt;snextc();
            while(c != EOF &amp;&amp; !std::isspace(c)) c = buf-&gt;snextc();  
         } while(--value);

         return in;
      }

   private:
      int value;
};

std::string input = &quot;foo bar 10 20 hello 30&quot;
int a,b,c;
std::string garbage;
stringstream foo;
foo &lt;&lt; input;
input &gt;&gt; skip_strings(2) &gt;&gt; a &gt;&gt; b &gt;&gt; skip_strings(1) &gt;&gt; c;
</code></pre>
<p>ungetestet und aus dem kopf</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917598</guid><dc:creator><![CDATA[!meep meep!]]></dc:creator><pubDate>Sat, 26 Jun 2010 12:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to moeglichst elegant logfile parsen on Sat, 26 Jun 2010 15:16:04 GMT]]></title><description><![CDATA[<p>schöne idee, wie ich finde.<br />
nur die zeile</p>
<pre><code class="language-cpp">skip_strings(int val = 1) : value(val) { }
</code></pre>
<p>find ich doof.</p>
<ol>
<li>explicit vergessen?!</li>
<li>wieso default-parameter? (wer soll später bei <code>stream &gt;&gt; skip_strings() &gt;&gt; ...</code> wissen, was dort passiert?)</li>
<li>wieso signed?</li>
</ol>
<p>ich würde auch den namen in skip_dates oder so was in der richtung ändern.<br />
skip_strings klingt so, als ob er aufhören würde, wenn er an einer zahl angelangt ist.</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917652</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Sat, 26 Jun 2010 15:16:04 GMT</pubDate></item><item><title><![CDATA[Reply to moeglichst elegant logfile parsen on Sun, 27 Jun 2010 06:33:49 GMT]]></title><description><![CDATA[<p>(1) ja<br />
(2) keine ahnung wasich dabei gedacht habe<br />
(3) sollte unsigned sein sonst muesste es 'if(value &lt;= 0)' heissen</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917805</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917805</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 27 Jun 2010 06:33:49 GMT</pubDate></item><item><title><![CDATA[Reply to moeglichst elegant logfile parsen on Sun, 27 Jun 2010 07:04:12 GMT]]></title><description><![CDATA[<p>alpha21 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">std::string input = &quot;foo bar 10 20 hello 30&quot;
int a,b,c;
std::string garbage;
stringstream foo;
foo &lt;&lt; input;
input &gt;&gt; garbage &gt;&gt; garbage &gt;&gt; a &gt;&gt; b &gt;&gt; garbage &gt;&gt; c;
</code></pre>
<p>finde das aber nicht sehr effizient.</p>
</blockquote>
<p>Vollkommen ausreichend und kommt ohne zusätzliches gefrickel aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1917808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1917808</guid><dc:creator><![CDATA[ach]]></dc:creator><pubDate>Sun, 27 Jun 2010 07:04:12 GMT</pubDate></item></channel></rss>