Sponsored Content
Full Discussion: Sum with condition
Top Forums UNIX for Dummies Questions & Answers Sum with condition Post 302926556 by radius on Tuesday 25th of November 2014 06:48:25 AM
Old 11-25-2014
Sum with condition

Dear masters,

I have file input
Code:
011171646073|12129|12129|A027|20141001|20141015|2014|10|01|2013|10|15
011171646076|12129|12129|A027|20141001|20141012|2014|10|01|2014|09|12
011171646078|12129|12129|A027|20141001|20141015|2014|10|01|2014|10|15
011171646081|12129|12129|A027|20141001|20141016|2014|10|10|2014|10|08
011171646082|12129|12129|A027|20141001|20141014|2014|10|01|2014|10|14

I need to calculate as $13 with condition when column 10 >= column 8 and column 12 >=column 9 and column 13 >=column 10 then do
Code:
((($12-$10)*30) + ($12-$10))

I tried this code but it didnt meet my expectation

Code:
BEGIN { FS=OFS="|"; CONVFMT=OFMT="%.10g" }
$8 >= $11 && $12 >= $9 && $13>=$10 { $13 = ((($12-$10)*30) + ($12-$10)) }
else { $13 = "FALSE" }
{ print }

My Expected output

Code:
011171646073|12129|12129|A027|20141001|20141015|2014|10|01|2013|10|15|14
011171646076|12129|12129|A027|20141001|20141012|2014|10|01|2014|09|12|FALSE
011171646078|12129|12129|A027|20141001|20141015|2014|10|01|2014|10|15|14
011171646081|12129|12129|A027|20141001|20141016|2014|10|10|2014|10|08|FALSE
011171646082|12129|12129|A027|20141001|20141014|2014|10|01|2014|10|14|13

Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sum

Hello everyone I need to write a script that sums numbers passed to it as arguments on the command line and displays the results. I must use a for loop and then rewrite it using a while loop. It would have to output something like 10+20+30=60 this is what I have so far fafountain@hfc:~$ vi sum... (1 Reply)
Discussion started by: Blinky85
1 Replies

2. UNIX for Dummies Questions & Answers

sum of column with condition

1 IT 50 2 IT 40 3 Finance 200 4 MP 30 5 MP 10 6 HQ 30 how to use awk to make it display it like this IT 90 MP 40 HQ 30 Finance 200 (1 Reply)
Discussion started by: minwei86
1 Replies

3. Shell Programming and Scripting

Print sum and relative value of the sum

Hi i data looks like this: student 1 Subject1 45 55 Subject2 44 55 Subject3 33 44 // student 2 Subject1 45 55 Subject2 44 55 Subject3 33 44 i would like to sum $2, $3 (marks) and divide each entry in $2 and $3 with their respective sums and print for each student as $4 and... (2 Replies)
Discussion started by: saint2006
2 Replies

4. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

5. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

How to sum these value.

Hi, Unix Gurus, I need sum values from a file. file format like: 0004004 0000817 0045000 0045000 0045000 0045000 0045000 0045000 0045000 0045000 0045000 0045000 0004406 the result should be 459227 (817+45000 ... + 4406) anybody can help me out (7 Replies)
Discussion started by: ken002
7 Replies

7. Shell Programming and Scripting

Sum with condition

Hi all, I have question on how to sum up a column with "condition" for following listing example imvprd_lun01 34 imvprd_pool01 admin 19 imv1prd_lun01 188 IMBDW_N0 imvprd_pool01 admin 133 imv1prd_lun02 1236 IMBDW_N1 imvprd_pool01 admin 1125 imv1prd_lun03... (2 Replies)
Discussion started by: ckwan
2 Replies

8. Shell Programming and Scripting

Sum Of Column Based On Column Condition

I have a following inputfile MT,AP,CDM,TTML,MUM,GS,SUCC,3 MT,AP,CDM,TTSL,AP,GS,FAIL,9 MT,AP,CDM,RCom,MAH,GS,SUCC,3 MT,AP,CDM,RTL,HP,GS,SUCC,1 MT,AP,CDM,Uni,UPE,GS,SUCC,2 MT,AP,CDM,Uni,MUM,GS,SUCC,2 TTSL,AP,GS,MT,MAH,CDM,SUCC,20 TTML,AP,GS,MT,MAH,CDM,FAIL,10... (2 Replies)
Discussion started by: siramitsharma
2 Replies

9. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

10. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies
GIT-COLUMN(1)							    Git Manual							     GIT-COLUMN(1)

NAME
git-column - Display data in columns SYNOPSIS
git column [--command=<name>] [--[raw-]mode=<mode>] [--width=<width>] [--indent=<string>] [--nl=<string>] [--padding=<n>] DESCRIPTION
This command formats its input into multiple columns. OPTIONS
--command=<name> Look up layout mode using configuration variable column.<name> and column.ui. --mode=<mode> Specify layout mode. See configuration variable column.ui for option syntax. --raw-mode=<n> Same as --mode but take mode encoded as a number. This is mainly used by other commands that have already parsed layout mode. --width=<width> Specify the terminal width. By default git column will detect the terminal width, or fall back to 80 if it is unable to do so. --indent=<string> String to be printed at the beginning of each line. --nl=<N> String to be printed at the end of each line, including newline character. --padding=<N> The number of spaces between columns. One space by default. AUTHOR
Written by Nguyen Thai Ngoc Duy <pclouds@gmail.com[1]> GIT
Part of the git(1) suite NOTES
1. pclouds@gmail.com mailto:pclouds@gmail.com Git 1.8.5.3 01/14/2014 GIT-COLUMN(1)
All times are GMT -4. The time now is 02:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy