hey all
I am trying to read & extract data from a trace file
I have created a program where I can count the number of received, sent, dropped pkts and then calculates the Received/Received+ Drop and it did compile successfully
I am now trying to count the number of lines that contain both the character r and the word AGT as well but when doing so I keep getting it as 0
Can u plz help me out.. I don't know what am I doing wrong ?
thanx in advance
input >>c; // puts entire line into single char?
input >>n; // puts entire line into string
if((c == 'r' )&&
(n =="AGT")) // this does not check if string CONTAINS "AGT".
// It checks if string EQUALS "AGT".
// "r - AGT - Hello" does not EQUAL "AGT".
I need to be careful what I ask for here. It would be helpful if you could show an example of the contents of the file - but not the entire file, just a few lines would do, to show the typical contents of the lines that you are interested in.
The [output] text here [/output] tags may be useful in order to preserve spacing.
ifstream fin("trace.txt");
string line;
string a, b, c, d;
while (getline(fin, line) )
{
istringstream ss(line);
ss >> a >> b >> c >> d;
if (a == "r" && d == "AGT")
cout << line << endl;
}
I see that the later part of each line may vary, but I assumed that all lines start out with the same layout, and each is field separated by whitespace.
Thank u soo much for the link and the code it is quite helpful and I did try the code and it successfully compiled
and that was the o/p
d = IFQ.
received pkts = 19495.
agent = 0.
send pkts =133958.
Dropped pkts =7836.
The number of lines = 268264
I don't get what does d= IFQ mean
and can u plz correct me if I understood this codeline in a wrong way ss >> a >> b >> c >> d; This codeline is written to scan through the line and get to the word ''AGT'' but what if I want to count the lines that have the words tcp and received and AGT or the r and the time (which is the second value).
thanx in advance
This line ss >> a >> b >> c >> d; simply splits the line into individual words whenever it finds whitespace.
With a slight modification, I get this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
ifstream fin("trace.txt");
string line;
string a, b, c, d, e, f, g;
while (getline(fin, line) )
{
istringstream ss(line);
ss >> a >> b >> c >> d >> e >> f >> g;
cout << "a: " << a << " b: " << b << " c: " << c << " d: " << d
<< " e: " << e << " f: " << f << " g: " << g << endl;
if (a == "r" && d == "AGT")
cout << line << endl;
}
Output:
a: r b: 11.101753057 c: _9_ d: MAC e: --- f: 30 g: tcp
a: s b: 11.101763057 c: _9_ d: MAC e: --- f: 0 g: ACK
a: r b: 11.101778057 c: _9_ d: AGT e: --- f: 30 g: tcp
r 11.101778057 _9_ AGT --- 30 tcp 1060 [13a 9 3 800] ------- [3:2 9:2 32 9] [2 0] 1 0<br>
a: s b: 11.101778057 c: _9_ d: AGT e: --- f: 40 g: ack
a: r b: 11.101778057 c: _9_ d: RTR e: --- f: 40 g: ack
a: s b: 11.101778057 c: _9_ d: RTR e: --- f: 40 g: ack
a: r b: 11.102067147 c: _3_ d: MAC e: --- f: 0 g: ACK
a: s b: 11.102257156 c: _2_ d: MAC e: --- f: 0 g: RTS
a: r b: 11.102609191 c: _3_ d: MAC e: --- f: 0 g: RTS
a: s b: 11.102619191 c: _3_ d: MAC e: --- f: 0 g: CTS
Here you can see that string g would be the one to check for "tcp".
It's just a matter of applying whatever tests or selection criteria you like to the appropriate variable.
Of course you might still find it useful to try string.find() but doing it this way allows you to home in directly on a particular column of data rather than searching the entire string.
hey all
i tried using the same code to print out and count some items in a similar trace file
r 3.507270487 _0_ MAC --- 3 ack 60 [13a 0 1 800] ------- [1:0 0:0 32 0] [0 0] 1 0
s 3.507280487 _0_ MAC --- 0 ACK 38 [0 1 0 0]
r 3.507295487 _0_ AGT --- 3 ack 60 [13a 0 1 800] ------- [1:0 0:0 32 0] [0 0] 1 0
s 3.507295487 _0_ AGT --- 4 tcp 1040 [0 0 0 0] ------- [0:0 1:0 32 0] [1 0] 0 0
r 3.507295487 _0_ RTR --- 4 tcp 1040 [0 0 0 0] ------- [0:0 1:0 32 0] [1 0] 0 0
s 3.507295487 _0_ RTR --- 4 tcp 1060 [0 0 0 0] ------- [0:0 1:0 32 1] [1 0] 0 0
s 3.507295487 _0_ AGT --- 5 tcp 1040 [0 0 0 0] ------- [0:0 1:0 32 0] [2 0] 0 0
r 3.507295487 _0_ RTR --- 5 tcp 1040 [0 0 0 0] ------- [0:0 1:0 32 0] [2 0] 0 0
s 3.507295487 _0_ RTR --- 5 tcp 1060 [0 0 0 0] ------- [0:0 1:0 32 1] [2 0] 0 0
r 3.507584536 _1_ MAC --- 0 ACK 38 [0 1 0 0]
s 3.507674487 _0_ MAC --- 0 RTS 44 [256e 1 0 0]
s 3.775336507 _0_ MAC --- 0 RTS 44 [256e 1 0 0]
s 6.033650740 _0_ MAC --- 335 tcp 1118 [13a 1 0 800] ------- [0:0 1:0 32 1] [176 0] 0 0
that's a snap shot of my code
ifstream myfile ("dees.tr");
if(myfile.is_open()) {
while (getline(myfile,line)) {
numlines++;
istringstream input(line);
input >> c >> b >> m >> d >> e >> f >> g >> h >> q >> i >> o >> j
>> k >> l >> y >> n >> p >> r;
cout << "c:" << c<< " b:" << b << " m:" << m << " g:" << g << " h:"
<< h << " q:" << q << " i:" << i << " o:" << o << " j:" << j << "k:"
<< k << " l:" << l << " y:" << y << " n:" << n << " p :" << p << " r:"
<< r << ".\n";
and that's the o/p
c:r b:3.507270487 m:_0_ g:ack h:60 q:[13a i:0 o:1 j:800]k:------- l:[1:0 y:0:0 n:32 p :0] r:[0.
c:s b:3.507280487 m:_0_ g:ACK h:38 q:[0 i:1 o:0 j:0]k:------- l:[1:0 y:0:0 n:32 p :0] r:[0.
c:r b:3.507295487 m:_0_ g:ack h:60 q:[13a i:0 o:1 j:800]k:------- l:[1:0 y:0:0 n:32 p :0] r:[0.
c:s b:3.507295487 m:_0_ g:tcp h:1040 q:[0 i:0 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :0] r:[1.
c:r b:3.507295487 m:_0_ g:tcp h:1040 q:[0 i:0 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :0] r:[1.
c:s b:3.507295487 m:_0_ g:tcp h:1060 q:[0 i:0 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :1] r:[1.
c:s b:3.507295487 m:_0_ g:tcp h:1040 q:[0 i:0 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :0] r:[2.
c:r b:3.507295487 m:_0_ g:tcp h:1040 q:[0 i:0 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :0] r:[2.
c:s b:3.507295487 m:_0_ g:tcp h:1060 q:[0 i:0 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :1] r:[2.
c:r b:3.507584536 m:_1_ g:ACK h:38 q:[0 i:1 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :1] r:[2.
c:s b:3.507674487 m:_0_ g:RTS h:44 q:[256e i:1 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :1] r:[2.
c:s b:3.775336507 m:_0_ g:RTS h:44 q:[256e i:1 o:0 j:0]k:------- l:[0:0 y:1:0 n:32 p :1] r:[2.
c:s b:6.033650740 m:_0_ g:tcp h:1118 q:[13a i:1 o:0 j:800]k:------- l:[0:0 y:1:0 n:32 p :1] r:[176.
The problem lies in the lines that stops at j (2,10,11,12), it starts to duplicate the rest of the above line which results in miscounting
for example
if i tried to count the l variable
if(l =="[0:0")
zero++;
o/p
zero = 10.
The result should be 7 when counted manually .. any ideas how can i make it at lines(2,10,11,12) stop at j and count the rest normally
thanx in advance