This is just an example with python with no checking the existence of the file or other and i have to say that i found all of this over the INTERNET i just put the pieces together so there may be many other ways to do this.
At the beggining i tougth that python were not so good because i does not have any hash structure but it has many other it simplifies the perl version of course im talking of my franken_perl_version (:{
#!/usr/bin/python
#Counter:
# A Counter is a container that tracks how many times equivalent values are
# added.It can be used to implement the same algorithms for which other
# languages commonly use bag or multi-set data structures.
import sys;
from collections import Counter;
users = [];
for line in open(sys.argv[1], "r"):
e = line.split();
users.append(e[8]);
c = Counter(users);
for k in users:
print '%s : %d' % (k, c[k]);
Friday, October 4, 2013
Thursday, October 3, 2013
Little_Script_Series: Perl script Count number of Times 4 word on FILE
Ok this is one of the first series on little scripts that i have just used on the work.
Some time ago i was wondering how many users were actually using the mail service either with IMAP or WEBMAIL access so i take parts from the code i found over internet and put it together the perl script needs the name of the file and the word that u want to match the log file that i was working were splitted with blank space so if u need another character just change it!
checkLogin.pl
usage: checkLotin.pl <loginfile.txt> <place of the word a number>
#!/usr/bin/perl
use strict;
use warnings;
my $num_args = $#ARGV+1;
my $c=0;
my %count_of;
my $user;
my $line;
my @val;
my $k;
my $v;
if($num_args == 0 || $num_args <= 1){
print ("wrong arguments\n usage: checkLogin.pl FILE POSITION\n");
}
else{
open(myFH,$ARGV[0]) or die("Cant open log file.");
foreach $line (<myFH>) {
chomp($line); # remove the newline from $line.
# do line-by-line processing.
@val = split(/\s+/,$line);
# select the word by position number.
$user = $val[$ARGV[1]];
$count_of{$user}++;
}
close(myFH);
while ( ($k,$v) = each %count_of ) {
print "$k => $v\n";
}
}
__END__
sorry for my bad programming skills but im a newbie, and for the bad english.
Some time ago i was wondering how many users were actually using the mail service either with IMAP or WEBMAIL access so i take parts from the code i found over internet and put it together the perl script needs the name of the file and the word that u want to match the log file that i was working were splitted with blank space so if u need another character just change it!
checkLogin.pl
usage: checkLotin.pl <loginfile.txt> <place of the word a number>
#!/usr/bin/perl
use strict;
use warnings;
my $num_args = $#ARGV+1;
my $c=0;
my %count_of;
my $user;
my $line;
my @val;
my $k;
my $v;
if($num_args == 0 || $num_args <= 1){
print ("wrong arguments\n usage: checkLogin.pl FILE POSITION\n");
}
else{
open(myFH,$ARGV[0]) or die("Cant open log file.");
foreach $line (<myFH>) {
chomp($line); # remove the newline from $line.
# do line-by-line processing.
@val = split(/\s+/,$line);
# select the word by position number.
$user = $val[$ARGV[1]];
$count_of{$user}++;
}
close(myFH);
while ( ($k,$v) = each %count_of ) {
print "$k => $v\n";
}
}
__END__
sorry for my bad programming skills but im a newbie, and for the bad english.
Life-Facts
Either i know that this post has nothing to do here i just dont want to create another blog so.
My history of yesterday i went at the grocery, i wanted a coffee and a bottle of water i took a cappuccino and went to pay, at that moment a man enter to the grocery and went direct to me asking for one coin he was wearing black pants and black shirt looked a little dirty and disheveled he said "can u please give me a coin so i can bought a beer" he was so honest and made me smile so i give it, he thanks me went for the bottle and when he came back he told me that i was a good man because not everyone wants to give even a coin he smile me and says that he likes to pray to jesus and before i leave the grocery he told me that jesus will give me a hundred for that coin, i smiled to him again and go.
Later on afternoon i go again to grocery and bough a lottery ticket those one has to scratch and bingo i got 3 moons and earned 100 and remembered the guy and just got shocked since then im thinking about it. The man and Jesus.
My history of yesterday i went at the grocery, i wanted a coffee and a bottle of water i took a cappuccino and went to pay, at that moment a man enter to the grocery and went direct to me asking for one coin he was wearing black pants and black shirt looked a little dirty and disheveled he said "can u please give me a coin so i can bought a beer" he was so honest and made me smile so i give it, he thanks me went for the bottle and when he came back he told me that i was a good man because not everyone wants to give even a coin he smile me and says that he likes to pray to jesus and before i leave the grocery he told me that jesus will give me a hundred for that coin, i smiled to him again and go.
Later on afternoon i go again to grocery and bough a lottery ticket those one has to scratch and bingo i got 3 moons and earned 100 and remembered the guy and just got shocked since then im thinking about it. The man and Jesus.
Wednesday, October 2, 2013
How2 Solve compiling gcc -m32 cannot find crt1.o: No such file or directory
Im learning asm stuff so in the future i mean the future i can eventually get at the security field to knowing about xploits so i have a amd64 machine but many examples comes in 32bits asm programs so in my ubuntu based machine MINT i have to compile with 32bits option but i was not sure if i can do this so the google-fu save and check that i need to put the option -m32 on gcc so i try it out
$ gcc -m32 -o example example1.c
but i get:
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status
$
... so google-fu again and find that i have to actually install multilib for gcc so i check out the version of my gcc and use the GUI to manage the packet but actually in the command will be
$ sudo apt-get install gcc-4.6-multilib
after this
$ gcc -m32 -o example example1.c
and then OK
$ objdump -m intel -d example1
80482d8: 53 push %ebx
80482d9: 83 ec 08 sub $0x8,%esp
80482dc: e8 00 00 00 00 call 80482e1 <_init+0x9>
80482e1: 5b pop %ebx
80482e2: 81 c3 13 1d 00 00 add $0x1d13,%ebx
80482e8: 8b 83 fc ff ff ff mov -0x4(%ebx),%eax
80482ee: 85 c0 test %eax,%eax
$ gcc -m32 -o example example1.c
but i get:
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status
$
... so google-fu again and find that i have to actually install multilib for gcc so i check out the version of my gcc and use the GUI to manage the packet but actually in the command will be
$ sudo apt-get install gcc-4.6-multilib
after this
$ gcc -m32 -o example example1.c
and then OK
$ objdump -m intel -d example1
80482d8: 53 push %ebx
80482d9: 83 ec 08 sub $0x8,%esp
80482dc: e8 00 00 00 00 call 80482e1 <_init+0x9>
80482e1: 5b pop %ebx
80482e2: 81 c3 13 1d 00 00 add $0x1d13,%ebx
80482e8: 8b 83 fc ff ff ff mov -0x4(%ebx),%eax
80482ee: 85 c0 test %eax,%eax
Subscribe to:
Posts (Atom)