Counting the differences based on a specific rule


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting the differences based on a specific rule
# 8  
Old 09-08-2008
Welp, my original proposal was to just collect the @differences, then at the end sort it and loop over it.

Code:
my %limits = (100 => "< 100",
  200 => "100 - 200",
  500 => "201 - 500",
  750 => "501 - 750",
  1000 => "751 - 1000",
  1_000_000_000 => "> 1001");
my @l = sort keys %limits;
my $total = 0;
print "\nDistribution:\n";
for my $d (sort @differences) {
  if ($d < $l[0]) {
    $total++;
    next;
  }
  print $limits{$l[0]}, "\t-\t", $total, "\n";
  shift @l;
}
print $limits{$l[0]}, "\t-\t", $total, "\n";

(Not tested.)
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux/Shell script - How to compare 2 arrays based on patterns and get the differences

I have FILE 1 (This file has all master columns/headers) A|B|C|D|E|F|G|H|STATUS FILE 2 A|C|F|I|OFF_STATUS 3|4|5|4|Y 6|7|8|5|Y Below command give me all headers of FILE 2 into array2.txt file paste <(head -1 FILE2.txt | tr '|' '\n')>array2.txt So I would like to compare... (2 Replies)
Discussion started by: jmadhams
2 Replies

2. UNIX for Dummies Questions & Answers

Extracting combined differences based on a single column

Dear All, I have two sets of files. File 1 can be any number between 1 and 20 followed by a frequency of that number in a give documents... the lines in the file will be dependent to the analysed document. e.g. file1 1,5 4,1 then I have file two which is basicall same numbers but with... (2 Replies)
Discussion started by: A-V
2 Replies

3. IP Networking

Facing issue in ip6table rule for port based routing management

Hi, Please help me on issue described below, I have 4 machine setup, M1 -> M2 -> M3 | M4. And A laptop that can be reachable through both M3 and M4. M2 has 2 NIC conected to M3 and M4. Now I want to divide the flow coming from M1 for laptop. At M2, I have done following,... (1 Reply)
Discussion started by: rahulbhansali24
1 Replies

4. Shell Programming and Scripting

Counting non-specific occurrences within a file.

I'm pretty new to scripting and didn't see an example of this issue yet. I am trying to count and print the total number of times each value is found within a file. Here is a short example of my starting file. value 3 value 3 value 3 value 3 value 4 value 6 value 6 value 6 value 6... (3 Replies)
Discussion started by: funkynmr
3 Replies

5. Shell Programming and Scripting

Regex based Rule engine.

Hi, Greetings. We need to make a regexp based rule engine. The rules would be applied to any file specified and the data not matching should be logged. Would awk be the right scripting language. Regards, Dikesh Shah. (2 Replies)
Discussion started by: dikesm
2 Replies

6. Shell Programming and Scripting

Counting specific words from the log

Hi, I need a shell script which can provide details from error logs like this Aug 23 21:19:41 red mountd: authenticated mount request from bl0110.bang.m pc.local:651 for /disk1/jobs (/disk1) Aug 23 08:49:52 red dhcpd: DHCPDISCOVER from 00:25:90:2b:cd:7c via eth0: unknown client Aug 24... (2 Replies)
Discussion started by: ratheeshp
2 Replies
Login or Register to Ask a Question
diffmk(1)						      General Commands Manual							 diffmk(1)

NAME
diffmk - Marks differences between files SYNOPSIS
diffmk [-b] [-ab'mark'] [-ae'mark'] [-cb'mark'] [-ce'mark'] [-db'mark'] [-de'mark'] file1 file2 The diffmk command compares two versions of a file and creates a new file that marks the differences. OPTIONS
Uses mark to mark where added lines begin. Uses mark to mark where added lines end. Ignores differences that are only changes in tabs or spaces on a line. Uses mark to mark where changed lines begin. Uses mark to mark where changed lines end. Uses mark to mark where deleted lines begin. Uses mark to mark where deleted lines end. DESCRIPTION
The file1 and file2 variables are the old and new versions of the file, respectively. The diffmk command compares them and writes a new version to standard output, which can be redirected to a file. This output contains the lines of file2 marked with nroff change mark requests (.mc), or with the marks you specify with the -ab, -ae, -cb, -ce, -db, and -de options. When output containing requests is formatted with nroff, changed or inserted lines are marked by a | (vertical bar) at the right margin of each line. An * (asterisk) indicates that a line was deleted. If the DIFFMARK environment variable is defined, it names a command string that diffmk uses to compare the files. (Normally, diffmk uses the diff command.) For example, you might set DIFFMARK to diff -h in order to better handle extremely large files. EXAMPLES
To mark the differences between two versions of a text file, enter: diffmk -ab'>I:' -ae'<I' -cb'>C' -ce'<C' -db'>D' -de'<D' chap1.old chap1 >chap1.diffs This causes diffmk to create a copy of chap1 called chap1.diffs, showing differences between chap1.old and chap1. Additions of one or more lines are marked with >I and <I, changed lines are marked with >C and <C, and deletions are marked with >D and <D. To mark differences with nroff requests, enter: diffmk chap1.old chap1 > chap1.nroff This produces a copy of chap1 called chap1.nroff containing nroff change mark requests to identify text that was added to, changed, or deleted from chap1.old. To use different nroff marking requests and ignore changes in white space, enter: diffmk -b -cb'.mc %' chap1.old chap1 > chap1.nroff This imbeds commands that mark changes with % (percent sign), additions with | (the default, because no -a option is specified), and deletions with * (the default). It does not mark changes that only involve a different number of spaces or tabs between words (-b). SEE ALSO
Commands: diff(1), nroff(1) diffmk(1)