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
ecvt(3) 						     Library Functions Manual							   ecvt(3)

NAME
ecvt, ecvt_r, fcvt, fcvt_r, gcvt - Convert a floating-point number to a string LIBRARY
Standard C Library (libc.a) SYNOPSIS
#include <stdlib.h> char *ecvt( double value, int num_digits, int *decimal_ptr, int *sign); char *fcvt( double value, int num_digits, int *decimal_ptr, int *sign); char *gcvt( double value, int num_digits, char *buffer); The following obsolete functions are supported in order to maintain backward compatibility with previous versions of the operating system. You should not use them in new designs. int ecvt_r( double value, int num_digits, int *decimal_ptr, int *sign, char *buffer, int len ); int fcvt_r( double value, int num_digits, int *decimal_ptr, int *sign, char *buffer, int len ); PARAMETERS
Specifies the double value to be converted. Specifies the number of digits in the resulting string. Holds the position of the decimal point relative to the beginning of the string. A negative number means the decimal point is to the left of the digits given in the string. Holds a value of 0 (zero) if the value is positive or zero, and a nonzero value if it is negative. Specifies the character array to be used as scratch space in calculations and for storing the resulting string. Specifies the length of buffer. Because ecvt temporarily stores intermediate results of its calculations in the buffer, you must specify a len greater than 370. A value of 400 is recommended. DESCRIPTION
The ecvt(), fcvt(), and gcvt() functions convert floating-point numbers to null-terminated strings. The ecvt() function converts the value specified by the value parameter to a null-terminated string of length num_digits, and returns a pointer to it. The resulting low-order digit is rounded according to the current rounding mode. The decimal_ptr parameter is assigned to the position of the decimal point relative to the position of the string. The sign parameter is assigned a value of 0 (zero) if value is positive or zero, and a nonzero value if value is negative. The decimal point and sign are not included in the string. The fcvt() function is the same as the ecvt() function, except that it rounds to the correct digit for outputting num_digits of digits in C or FORTRAN F-format. In the F-format, num_digits is taken as the number of digits desired after the decimal point. The gcvt() function converts the value specified by the value parameter to a null-terminated string, stores it in the array pointed to by the buffer parameter, and then returns buffer. The gcvt() function attempts to produce a string of num_digits significant digits in FOR- TRAN F-format. If this is not possible, then E-format is used. The string is ready for printing, complete with minus sign, decimal point, or exponent, as appropriate. Trailing zeros are suppressed. In the F-format, num_digits is the number of digits desired after the decimal point. Very large numbers produce a very long string of dig- its before the decimal point, and then num_digits of digits after the decimal point. For large numbers, it is preferable to use the gcvt() or ecvt() function so that the E-format will be used. The ecvt(), fcvt(), and gcvt() functions represent the following special values that are specified in IEEE Standard 754-1985 for floating- point arithmetic according to the following table. Value Representation -------------------------------- Quiet NaN NaNQ Signalling NaN NaNS +Infinity INF -Infinity -INF The sign associated with each of these values is stored into the sign parameter. Note, also, that in IEEE floating point operations, a value of 0 (zero) can be positive or negative, as set by the sign parameter. NOTES
The ecvt(), fcvt(), and gcvt() functions store the converted string in a thread-specific buffer. Subsequent calls to these functions from the same thread overwrite the contents of the internal buffer. The ecvt_r() and fcvt_r() functions are obsolete reentrant versions of the ecvt() and fcvt() functions. They are supported in order to maintain backward compatibility with previous versions of the operating system and should not be used in new designs. RETURN VALUES
The ecvt(), fcvt(), and gcvt() functions return the converted string. Upon successful completion, the ecvt_r() and fcvt_r() functions store the converted string in the array pointed to by the buffer parameter, and return a value of 0 (zero). Upon failure, these functions return -1 and may set errno. ERRORS
If the ecvt_r() or fcvt_r() function fails, errno may be set to the following value: The buffer parameter is invalid or too small. RELATED INFORMATION
Functions: atof(3), printf(3), scanf(3). delim off ecvt(3)
All times are GMT -4. The time now is 11:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy