Sponsored Content
Top Forums Shell Programming and Scripting Help with figuring division and addition based on column data and line numbers Post 302623211 by ncwxpanther on Friday 13th of April 2012 09:45:51 AM
Old 04-13-2012
Thanks it works like you said up until the last set up to a certain point.

For some reason the first column is +1 more than it should be.

For instance

2006 54

returns

2007.2354 54

Also, when there is a decimal in the 2nd column values like

2006 41.5

The value return is

2007.2241.5 41.5

The real input file looks something like this

2006-01-01 55.4
1531-10-14 100.9

I need the following format in the output
2006.00274 55.4
1531.00548 100.9
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find different column numbers among rows in data

I want to find the different column numbers among rows in a file. For example: A001 a b c d e ... N A002 a b c d e ... N A003 a b c d e ... N+1 A004 a b c d e ... N A005 a b c d e ... N+2 : : For most of the lines I will have N columns (say 1000 rows) in each line except the line 3... (5 Replies)
Discussion started by: AMBER
5 Replies

2. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

3. Shell Programming and Scripting

Remove duplicate line detail based on column one data

My input file: AVI.out <detail>named as the RRM .</detail> AVI.out <detail>Contains 1 RRM .</detail> AR0.out <detail>named as the tellurite-resistance.</detail> AWG.out <detail>Contains 2 HTH .</detail> ADV.out <detail>named as the DENR family.</detail> ADV.out ... (10 Replies)
Discussion started by: patrick87
10 Replies

4. Shell Programming and Scripting

How to fetch rows based on line numbers or based on the beginning of a word?

I have a file which will have rows like shown below, ST*820*316054716 RMR*IV*11333331009*PO*40.31 REF*IV*22234441009*xsss471-2762 DTM*003*091016 ENT*000006 RMR*IV*2222234444*PO*239.91 REF*IV*1234445451009*LJhjlkhkj471-2762 </SPAN> DTM*003* 091016 RMR*IV*2223344441009*PO*40.31... (18 Replies)
Discussion started by: Muthuraj K
18 Replies

5. Shell Programming and Scripting

Generate Codes based on start and End values of numbers in a column

Hello All, Could you please help with this. This is what I have: 506234.222 2 506234.222 2 506234.222 2 506234.222 2 508212.200 2 508212.200 2 333456.111 2 333456.111 2 333456.111 2 333456.111 2 But this is what I want: 506234.222 1 506234.222 2 506234.222 2 506234.222 3 (5 Replies)
Discussion started by: canimba
5 Replies

6. Shell Programming and Scripting

Split a file into multiple files based on line numbers and first column value

Hi All I have one query,say i have a requirement like the below code should be move to diffent files whose maximum lines can be of 10 lines.Say in the below example,it consist of 14 lines. This should be moved logically using the data in the fisrt coloumn to file1 and file 2.The data of first... (2 Replies)
Discussion started by: sarav.shan
2 Replies

7. UNIX for Dummies Questions & Answers

Assigning rank to rows of numbers based on the last column

I have a tab delimited text file that looks like the following: ERBB3 0.00097 IL31RA 0.000972 SETD5 0.000972 MCART1 0.000973 CENPJ 0.000973 FNDC6 0.000974 I want to assign a number to each row based on the value in the last column (in the order of increasing value so that the first row... (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

9. Shell Programming and Scripting

Extracting values based on line-column numbers from multiple text files

Dear All, I have to solve the following problems with multiple tab-separated text file but I don't know how. Any help would be greatly appreciated. I have access to Linux mint (but not as a professional). I have multiple tab-delimited files with the following structure: file1: 1 44 2 ... (5 Replies)
Discussion started by: Bastami
5 Replies

10. Shell Programming and Scripting

To append new data at the end of each line based on substring of last column

Hi guys, I need to append new data at the end of each line of the files. This new data is based on substring (3rd fields) of last column. Input file xxx.csv: U1234|1-5X|orange|1-5X|Act|1-5X|0.1 /sac/orange 12345 0 U5678|1-7X|grape|1-7X|Act|1-7X|0.1 /sac/grape 5678 0... (5 Replies)
Discussion started by: null7
5 Replies
RCALC(1)						      General Commands Manual							  RCALC(1)

NAME
rcalc - record calculator SYNOPSIS
rcalc [ -b ][ -l ][ -p ][ -n ][ -w ][ -u ][ -tS ][ -i format ][ -o format ][ -f source ][ -e expr ][ -s svar=sval ] file .. DESCRIPTION
Rcalc transforms ``records'' from each file according to the given set of literal and relational information. By default, records are sep- arated by newlines, and contain numeric fields separated by tabs. The -tS option is used to specify an alternate tab character. A -i format option specifies a template for an alternate input record format. Format is interpreted as a specification string if it con- tains a dollar sign '$'. Otherwise, it is interpreted as the name of the file containing the format specification. In either case, if the format does not end with a newline, one will be added automatically. A special form of the -i option may be followed immediately by a 'd' or an 'f' and an optional count, which defaults to 1, indicating the number of double or float binary values to read per record on the input file. If the input is byte-swapped, the -iD or -iF options may be substituted. If binary input is specified, no format string or file is needed. A -o format option specifies an alternate output record format. It is interpreted the same as an input specification, except that the spe- cial -od or -of options do not require a count, as this will be determined by the number of output channels in the given expressions. If byte-swapped output is desired, the -oD or -oF options may be substituted. The -p option specifies "passive mode," where characters that do not match the input format are passed unaltered to the output. This option has no effect unless -i is also specified, and does not make much sense unless -o is also given. With both input and output for- mats, the passive mode can effectively substitute information in the middle of a file or stream without affecting the rest of the data. The variable and function definitions in each -f source file are read and compiled. The -e expr option can be used to define variables on the command line. Since many of the characters in an expression have special meaning to the shell, it should usually be enclosed in single quotes. The -s svar=sval option can be used to assign a string variable a string value. If this string variable appears in an input for- mat, only records with the specified value will be processed. The -b option instructs the program to accept only exact matches. By default, tabs and spaces are ignored except as field separators. The -l option instructs the program to ignore newlines in the input, basically treating them the same as tabs and spaces. Normally, the begin- ning of the input format matches the beginning of a line, and the end of the format matches the end of a line. With the -l option, the input format can match anywhere on a line. The -w option causes non-fatal error messages (such as division by zero) to be supressed. The -u option causes output to be flushed after each record. The -n option tells the program not to get any input, but to produce a single output record. Otherwise, if no files are given, the standard input is read. Format files associate names with string and numeric fields separated by literal information in a record. A numeric field is given in a format file as a dollar sign, followed by curly braces enclosing a variable name: This is a numeric field: ${vname} A string variable is enclosed in parentheses: This is a string field: $(sname) The program attempts to match literal information in the input format to its input and assign string and numeric fields accordingly. If a string or numeric field variable appears more than once in the input format, input values for the corresponding fields must match (ie. have the same value) for the whole record to match. Numeric values are allowed some deviation, on the order of 0.1%, but string variables must match exactly. Thus, dummy variables for "don't care" fields should be given unique names so that they are not all required to take on the same value. For each valid input record, an output record is produced in its corresponding format. Output field widths are given implicitly by the space occupied in the format file, including the dollar sign and braces. This makes it impossible to produce fields with fewer than four characters. If the -b option is specified, input records must exactly match the template. By default, the character following each input field is used as a delimiter. This implies that string fields that are followed by white space cannot contain strings with white space. Also, numeric fields followed but not preceded by white space will not accept numbers preceded by white space. Adjacent input fields are advisable only with the -b option. Numeric output fields may contain expressions as well as variables. A dollar sign may appear in a lit- eral as two dollar signs ($$). The definitions specified in -e and -f options relate numeric output fields to numeric input fields. For the default record format, a field is a variable of the form $N, where N is the column number, beginning with 1. Output columns appear on the left-hand side of assign- ments, input columns appear on the right-hand side. A variable definition has the form: var = expression ; Any instance of the variable in an expression will be replaced with its definition. An expression contains real numbers, variable names, function calls, and the following operators: + - * / ^ Operators are evaluated left to right. Powers have the highest precedence; multiplication and division are evaluated before addition and subtraction. Expressions can be grouped with parentheses. All values are double precision real. A function definition has the form: func(a1, a2, ..) = expression ; The expression can contain instances of the function arguments as well as other variables and functions. Function names can be passed as arguments. Recursive functions can be defined using calls to the defined function or other functions calling the defined function. The variable cond, if defined, will determine whether the current input record produces an output record. If cond is positive, output is produced. If cond is less than or equal to zero, the record is skipped and no other expressions are evaluated. This provides a convenient method for avoiding inappropriate calculations. The following library of pre-defined functions and variables is provided: in(n) Return the value for input column n, or the number of columns available in this record if n is 0. This is an alternate way to get a column value instead of using the $N notation, and is more flexible since it is programmable. This function is disabled if an input format is used. if(cond, then, else) if cond is greater than zero, then is evaluated, otherwise else is evaluated. This function is necessary for recursive defini- tions. select(N, a1, a2, ..) return aN (N is rounded to the nearest integer). This function provides array capabilities. If N is zero, the number of avail- able arguments is returned. rand(x) compute a random number between 0 and 1 based on x. floor(x) return largest integer not greater than x. ceil(x) return smallest integer not less than x. sqrt(x) return square root of x. exp(x) compute e to the power of x (e approx = 2.718281828). log(x) compute the logarithm of x to the base e. log10(x) compute the logarithm of x to the base 10. PI the ratio of a circle's circumference to its diameter. recno the number of records recognized thus far. outno the number or records output thus far (including this one). sin(x), cos(x), tan(x) trigonometric functions. asin(x), acos(x), atan(x) inverse trigonometric functions. atan2(y, x) inverse tangent of y/x (range -pi to pi). EXAMPLE
To print the square root of column two in column one, and column one times column three in column two: rcalc -e '$1=sqrt($2);$2=$1*$3' inputfile > outputfile AUTHOR
Greg Ward BUGS
String variables can only be used in input and output formats and -s options, not in definitions. Tabs count as single spaces inside fields. SEE ALSO
cnt(1), ev(1), getinfo(1), icalc(1), rlam(1), tabfunc(1), total(1) RADIANCE
4/6/99 RCALC(1)
All times are GMT -4. The time now is 02:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy