I am reading through a large log file of bans, and from those bans I want to specify a name within that line (see John below). I then want to print out only the IP of that line. Here are a few lines from an example log file:
[13:42:51] james preston (IP: 11.111.11.11) was banned by john
[13:42:51] gerald farmer (IP: 222.22.222.22) was offline banned by James
[13:42:51] luke parker (IP: 33.33.333.333) was banned by john
So far I can get the lines of the bans containing "john" however I would like to then extract the IP address from those lines.
int main() {
ifstream BanLogs;
BanLogs.open("ban-2019.log");
// Checking to see if the file is open
if (BanLogs.fail()) {
cerr << "ERROR OPENING FILE" << endl;
exit(1);
}
string item;
string name = "john";
int count = 0;
//read a file till the end
while (getline(BanLogs, item)) {
// If the line (item) contains a certain string (name) proceed.
if (item.find(name) != string::npos) {
cout << item << endl;
count++;
}
}
cout << "Number of lines " << count << endl;
return 0;
}