03-07-2009
A better way using perl
=========================================
#!/usr/bin/perl -w
$PORT=0;
$OPEN=0;
$TRANS=0;
$FAIL=0;
unless (open(INPUT, "<test5.txt")) {
die ("cannot open input, check permissions\n");
}
unless (open(OUTPUT, ">output.txt")) {
die ("cannot open output, check permissions\n");
}
while ($line = <INPUT>) {
if ($line =~ /200/) {
$PORT++;
}
elsif ($line =~ /150/) {
$OPEN++;
}
elsif ($line =~ /226/) {
$TRANS++;
}
elsif ($line =~ /not connected/i) {
$FAIL++;
}
}
print OUTPUT "PORT: $PORT\n";
print OUTPUT "OPEN: $OPEN\n";
print OUTPUT "TRANS: $TRANS\n";
print OUTPUT "FAIL: $FAIL\n";
close (INPUT);
close (OUTPUT);
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I need the total of how many times the pattern is being repeated in a particular file.
I tried with grep as below, but no go.
grep -c best sample
Contents of Sample file:
-----------------------
This is the best site I have never come across. The best one indeed.
Very best... (8 Replies)
Discussion started by: venkatesht
8 Replies
2. UNIX for Dummies Questions & Answers
Hi
I am new to the forum and would like to ask:
i have a file in form with thousands of column
id.1 A01 A01 A68 A68
id.2 A5 A5 A3 A3
1001 0 0 0.136 0.136
1002 0 0 0.262 0.183
1003 0 0 0.662 0.662
1004 0 0 ... (9 Replies)
Discussion started by: newbeeuk
9 Replies
3. UNIX for Dummies Questions & Answers
I'm trying to count the number of times each word in the file exist
for example if the file has:
today I have a lot to write, but I will not go for it. The main thing is that today I am looking for a way to get each word in this file with a word count after it specifying that this word has... (4 Replies)
Discussion started by: shnkool
4 Replies
4. Shell Programming and Scripting
Hi all,
I have a file like this
ID 3BP5L_HUMAN Reviewed; 393 AA.
AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3;
DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot.
DT 05-JUL-2004, sequence version 1.
DT 05-SEP-2012, entry version 71.
FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies
5. Shell Programming and Scripting
Hello All, I have a file which has repeated lines. I want to print the lines which are repeated three times.
Please help. (3 Replies)
Discussion started by: ailnilanjan
3 Replies
6. Shell Programming and Scripting
Hi below is the input file, i need to find repeated words and sum up the values of it which is second field from the repeated work.Im trying but getting no where close to it.Kindly give me a hint on how to go about it
Input
fruits,apple,20,fruits,mango,20,veg,carrot,12,veg,raddish,30... (11 Replies)
Discussion started by: 100bees
11 Replies
7. Homework & Coursework Questions
1. The problem statement, all variables and given/known data:
Develop a shell script that accepts a phrase and counts the number of times that it is repeated in a specific website.
Note: Im not sure if it's the whole website, or just a specific page but im guessing its thewhole website.
... (2 Replies)
Discussion started by: Zakerii
2 Replies
8. UNIX for Dummies Questions & Answers
Hi folks,
Iam working on a bash script, i need to print how many times column 2 repeated at the end of each line.
Input.txt
COL1 COL2 COL3 COL4
1 XX 45 N
2 YY 34 y
3 ZZ 44 N
4 XX 89 Y
5 XX 45 N
6 YY 84 D
7 ZZ 22 S
Output.txt
COL1 COL2 COL3 COL4 COL5
1 XX 45 N 3
2 YY 34... (6 Replies)
Discussion started by: tech_frk
6 Replies
9. UNIX for Beginners Questions & Answers
Dears
i want to extract lines only that have first entry repeated 3 times or above , ex data :
-bash-3.00$ cat INTCONT-IS.CSV
M205-00-106_AMDRN:1-0-6-22,12-662-4833,intContact,2016-11-15 02:32:16,50
M205-00-106_AMDRN:1-0-23-17,12-616-0462,intContact,2016-11-15 02:32:23,50... (5 Replies)
Discussion started by: is2_egypt
5 Replies
10. Shell Programming and Scripting
Remove duplicate lines which has been repeated 4 times attached test.txt
below command tried and not getting expect output.
for i in `cat test.txt | uniq`
do
num=`cat test.txt | grep $i | wc -l`
echo $i $num
done
test.txt
... (17 Replies)
Discussion started by: Kalia
17 Replies
LEARN ABOUT DEBIAN
mime::explode
Explode(3pm) User Contributed Perl Documentation Explode(3pm)
NAME
MIME::Explode - Perl extension for explode MIME messages
SYNOPSIS
use MIME::Explode;
my $explode = MIME::Explode->new(
output_dir => "tmp",
mkdir => 0755,
decode_subject => 1,
check_content_type => 1,
content_types => ["image/gif", "image/jpeg", "image/bmp"],
types_action => "exclude"
);
print "Number of messages: ", $explode->nmsgs, "
";
open(MAIL, "<file.mbox") or
die("Couldn't open file.mbox for reading: $!
");
open(OUTPUT, ">file.tmp")
or die("Couldn't open file.tmp for writing: $!
");
my $headers = $explode->parse(*MAIL, *OUTPUT);
close(OUTPUT);
close(MAIL);
for my $part (sort{ $a cmp $b } keys(%{$headers})) {
for my $k (keys(%{$headers->{$part}})) {
if(ref($headers->{$part}->{$k}) eq "ARRAY") {
for my $i (0 .. $#{$headers->{$part}->{$k}}) {
print "$part => $k => $i => ", $headers->{$part}->{$k}->[$i], "
";
}
} elsif(ref($headers->{$part}->{$k}) eq "HASH") {
for my $ks (keys(%{$headers->{$part}->{$k}})) {
if(ref($headers->{$part}->{$k}->{$ks}) eq "ARRAY") {
print "$part => $k => $ks => ", join(($ks eq "charset") ? " " : "", @{$headers->{$part}->{$k}->{$ks}}), "
";
} else {
print "$part => $k => $ks => ", $headers->{$part}->{$k}->{$ks}, "
";
}
print "$part => $k => $ks => ", $headers->{$part}->{$k}->{$ks}, "
";
}
} else {
print "$part => $k => ", $headers->{$part}->{$k}, "
";
}
}
}
if(my $e = $explode->clean_all()) {
print "Error: $e
";
}
DESCRIPTION
MIME::Explode is perl module for parsing and decoding single or multipart MIME messages, and outputting its decoded components to a given
directory ie, this module is designed to allows users to extract the attached files out of a MIME encoded email messages or mailboxes.
METHODS
new([, OPTION ...])
This method create a new MIME::Explode object. The following keys are available:
output_dir
Directory where the decoded files are placed
mkdir => octal_number
If the value is set to octal number then make the output_dir directory (example: mkdir => 0755).
check_content_type => 0 or 1
If the value is set to 1 the content-type of file is checked
decode_subject => 0 or 1
If the value is set to 1 then the subject is decoded into a list.
$header->{'0.0'}->{subject}->{value} = [ARRAYREF];
$header->{'0.0'}->{subject}->{charset} = [ARRAYREF];
$subject = join("", @{$header->{'0.0'}->{subject}->{value}});
exclude_types => [ARRAYREF]
Not save files with specified content types (deprecated in next versions)
content_types => [ARRAYREF]
Array reference with content types for "include" or "exclude"
types_action => "include" or "exclude"
If the action is a "include", all attached files with specified content types are saved but if the action is a "exclude", no files
are saved except if its in the array of content types. If no array is specified, but the action is a "include", all attached files
are saved, otherwise all files are removed if action is a "exclude". The default action is "include".
parse(FILEHANDLE, FILEHANDLE)
This method parse the stream and splits it into its component entities. This method return a hash reference with all parts. The FILEHANDLE
should be a reference to a GLOB. The second argument is optional.
nmsgs
Returns the number of parsed messages.
clean_all
Cleans all files from the "output_dir" directory and then removes the directory. If an error happens returns it.
AUTHOR
Henrique Dias <henrique.ribeiro.dias@gmail.com>
CREDITS
Thanks to Rui Castro for the revision.
SEE ALSO
MIME::Tools, perl(1).
perl v5.14.2 2011-06-26 Explode(3pm)