Sponsored Content
Top Forums Shell Programming and Scripting Counting the differences based on a specific rule Post 302233549 by labrazil on Monday 8th of September 2008 03:25:52 AM
Old 09-08-2008
Thank you era! It makes sense now. what i did was this

Code:
while (<>) {
	chomp;
  #die "Invalid input" unless m/^(\d+) ([-+])$/);
  my ($number, $sign) = split("\t");  # as captured by the previous regex match
  if ($sign eq '+') {
    ++$plusses;
    $previous = $number;
    next;
  }
  # else, must be a minus
  --$plusses;
	push @differences, $number - $previous;
	print $number - $previous, "\n";
}

I wasn't sure if 'push @differences' was needed? So i just printed the values (I reversed the subtraction because I was getting negative numbers). I guess I can then use some if expressions to count each category.
 

6 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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
regex.h(3HEAD)							      Headers							    regex.h(3HEAD)

NAME
regex.h, regex - regular expression matching types SYNOPSIS
#include <regex.h> DESCRIPTION
The <regex.h> header defines the structures and symbolic constants used by the regcomp(), regexec(), regerror(), and regfree() functions. See regcomp(3C). The structure type regex_t contains the following member: size_t re_nsub number of parenthesized subexpressions The type size_t is defined as described in <sys/types.h>. See types.h(3HEAD). The type regoff_t is defined as a signed integer type that can hold the largest value that can be stored in either a type off_t or type ssize_t. The structure type regmatch_t contains the following members: regoff_t rm_so byte offset from start of string to start of substring regoff_t rm_eo byte offset from start of string of the first character after the end of substring Values for the cflags parameter to the regcomp function are as follows: REG_EXTENDED use extended regular expressions REG_ICASE ignore case in match REG_NOSUB report only success or fail in regexec() REG_NEWLINE change the handling of NEWLINE character Values for the eflags parameter to the regexec() function are as follows: REG_NOTBOL The circumflex character (^), when taken as a special character, does not match the beginning of string. REG_NOTEOL The dollar sign ($), when taken as a special character, does not match the end of string. The following constants are defined as error return values: REG_NOMATCH regexec() failed to match. REG_BADPAT Invalid regular expression. REG_ECOLLATE Invalid collating element referenced. REG_ECTYPE Invalid character class type referenced. REG_EESCAPE Trailing '' in pattern. REG_ESUBREG Number in fIdigit invalid or in error. REG_EBRACK "[]" imbalance. REG_EPAREN "()" or "()" imbalance. REG_EBRACE "" imbalance. REG_BADBR Content of "" invalid: not a number, number too large, more than two numbers, first larger than second. REG_ERANGE Invalid endpoint in range expression. REG_ESPACE Out of memory. REG_BADRPT '?', '*', or '+' not preceded by valid regular expression. REG_ENOSYS Reserved. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
regcomp(3C), types.h(3HEAD), attributes(5), standards(5) SunOS 5.11 9 Sep 2004 regex.h(3HEAD)
All times are GMT -4. The time now is 01:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy