Skip to content

Instantly share code, notes, and snippets.

@spumer
Last active December 21, 2015 12:28
Show Gist options
  • Save spumer/6305790 to your computer and use it in GitHub Desktop.
Save spumer/6305790 to your computer and use it in GitHub Desktop.
Log stripper. Used for strip Sourcemod cmd_*.log files. Line will be skipped if pattern from dictionary will be found. How to use: * Linux: use "log_stripper.sh /path/to/log/dirs/" i recommend create one dir with symlinks to log dirs, for more performance * Windows: drag file to .exe or use command "stripper you_file.log" and stripped version wi…
#!/bin/bash
ionice -c3 -p$$
cd $(dirname $0)
LOGFILE=`find $1 -name "cmd_$(date +%m.%d.%y --date='(date) - 1 day').log"`
for file in $LOGFILE;do
echo $file
cat $file | ./stripper > $file.stripped
done
/*
Log-Stripper. Delete lines where pattern found. Patterns list in words.txt
Copyright (C) 2012 spumer (http://forums.alliedmods.net/member.php?u=151387)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LINE_SIZE 1024
const char* mystrstr(const char *dest, const char* source, size_t len);
int main(int argc, char **argv){
memcpy(strrchr(argv[0], '/')+1, "words.txt", 10);
FILE *ifs = fopen(argv[0], "rb");
if( ifs == NULL ) { fputs("File error!", stderr); return 1; }
//read file
fseek(ifs, 0, SEEK_END);
size_t len = ftell(ifs);
char *words = (char*)malloc(sizeof(char)*len);
if( words == NULL ) { fputs("Memory error", stderr); return 2; }
rewind(ifs);
words[len] = '\n';
fread(words, sizeof(char), len, ifs);
fclose(ifs);
//search patterns
register char *s;
char buf[LINE_SIZE];
while( fgets(buf, LINE_SIZE, stdin) != NULL ){
s = words;
while(*s != '\0') {
len = strchr(s, '\n') - s;
if( len && mystrstr(buf, s, len) ) goto next;
s += len + 1;
}
fputs(buf, stdout);
next: ;
}
free(words);
return 0;
}
const char* mystrstr(const char *dest, const char* source, size_t len) {
//if( !len ) return 0;
register const char *s = source;
while( *dest != '\0' ) {
if(*dest++ == *s) {
if( (++s-source) == len ) return dest;
}
else s = source;
}
return 0;
}
/*
Log-Stripper. Delete lines where pattern found. Patterns list in words.txt
Copyright (C) 2012 spumer (http://forums.alliedmods.net/member.php?u=151387)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include <fstream>
#include <iostream>
#include <string>
#include <list>
#include <unistd.h> // for readlink()
#include <libgen.h> // for dirname()
using namespace std;
string* getline(istream& input);
int main(void){
char buf[96];
if (readlink("/proc/self/exe", buf, 96) == -1) //http://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html
{ cout << "Error! Can't get path to myself!"; return 2; }
sprintf(buf, "%s/%s", dirname(buf), "words.txt");
ifstream ifs( buf );
if( !ifs.is_open() ) { cout << "Words file not found!"; return 1; }
list<string> words;
//read file
while ( ifs.peek() != EOF )
words.push_back(*getline(ifs));
ifs.close();
//search patterns
list<string>::iterator it;
string *buffer;
while( cin.peek() != EOF ){
buffer = getline(cin);
for(it = words.begin(); it != words.end(); ++it)
if( buffer->find( *it ) != string::npos)
goto next;
cout << *buffer << endl;
next: ;
}
return 0;
}
string* getline(istream& input){
static string str;
register char c;
str.clear();
while ( (c = input.get()) != '\n' )
str += c;
return &str;
}
/*
Log-Stripper. Delete lines where pattern found. Patterns list in words.txt
Copyright (C) 2012 spumer (http://forums.alliedmods.net/member.php?u=151387)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include <fstream>
#include <string>
#include <list>
#include <windows.h> //for GetMuduleFileName
#define WORD_SIZE 24
#define LINE_SIZE 1024
using namespace std;
string& SplitPaths(string& folder_of, string& filename_of);
int main(int argc, char *argv[]){
if(argc < 2) return -1;
char thisExe[128];
GetModuleFileName(0, thisExe, 128);
ifstream ifs( SplitPaths(string(thisExe), string("./words.txt")).c_str() );
list<string> words;
//read file
for(char buff[WORD_SIZE]; ifs.getline(buff, WORD_SIZE); )
words.push_back(string(buff));
ifs.close();
//search patterns
ifstream ifs1(argv[1]); // why i donot use "ifs object" ? ifs.open() not work for me.
ofstream ofs( SplitPaths(string(thisExe), string(argv[1])).c_str() );
list<string>::iterator it;
for(char buffer[LINE_SIZE]; ifs1.getline(buffer, LINE_SIZE); ){
for(it = words.begin(); it != words.end(); ++it)
if( int(string(buffer).find( *it )) != string::npos)
goto next;
ofs << buffer << endl;
next: continue;
}
ifs1.close(); ofs.close();
return 0;
}
string& SplitPaths(string& in, string& out){
size_t in_found, out_found;
in_found = in.find_last_of("/\\");
out_found = out.find_last_of("/\\");
return in.replace(in.begin()+in_found, in.end(),
out.begin()+out_found, out.end());
}
Console<0>
vmodenable
vban
spec_
say
menuopen
join
voicemenu
destroy
build
taunt
extendfreeze
menuselect
use_action_slot_item_server
dropitem
sm_t
sm_lt
vote
replay_togglereplaytips
demorestart
disguiseteam
showroundinfo
use tf_
timeleft
vocalize
choose_
kill
laser
director_force_panic_event
upgrade_add
go_away_from_keyboard
give
motd
achievement_earned
auto
z_spawn
ent_fire relay
survival_record
ready
pause
health
spectate
sm_team
sm_list
sm_vk
sm_infected
sm_takeover
sm_berserker
sm_buy
sm_perks
sm_switch
sm_donate
sm_csm
sm_gnom
sm_js
sm_ji
sm_afk
sm_tank
sm_vip
sm_servers
sm_go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment