Sponsored Content
Contact Us Post Here to Contact Site Administrators and Moderators How to Post in the The UNIX and Linux Forums How to get defined precision after arithmetic operation using syncsort? Post 303014607 by pumrao on Friday 16th of March 2018 01:21:18 AM
Old 03-16-2018
Lightbulb How to get defined precision after arithmetic operation using syncsort?

I have to do some arithmetic operation on Field 8 which is calculated by Field 9/Field 7

Suppose i have data like :
Code:
0800123456|JAN|2017|JAN|2018|0800123456|0|0.0000|0.00|
0800234567|JAN|2017|JAN|2018|0800234567|4|2.5812|10.32|
0800666666|JAN|2017|JAN|2018|0800666666|2|1.7255|3.45|
0800111111|DEC|2015|DEC|2018|0800111111|2|1.8312|7.32|
0800123456|JAN|2017|JAN|2018|0800123456|0|0.0000|0.00|
0800234567|JAN|2017|JAN|2018|0800234567|4|2.5812|10.32|
0800111111|DEC|2015|DEC|2018|0800111111|4|1.8312|7.32|

I used following code :
Code:
syncsort << endofsort
/INFILE $IN_FILE "|"

/fields
P_NUMBER 1:-1: en,
B_MONTH 2:-2:,
B_YEAR 3:-3: en,
D_MONTH 4:-4:,
D_YEAR 5:-5: en,
C_NUMBER 6:-6: en,
CALL_MINS 7:-7: en,
PRICE_PER_UNIT 8:-8: en,
AMOUNT 9:-9: en,

/CONDITION UNIT_PRICE_ZERO CALL_MINS = 0

/KEYS P_NUMBER ascending,B_MONTH ascending, B_YEAR ascending, D_MONTH ascending,D_YEAR ascending,C_NUMBER ascending

/SUMMARIZE
TOTAL CALL_COUNT,
TOTAL CALL_MINS,
TOTAL AMOUNT,

/DERIVEDFIELD NEW_PRICE_PER_UNIT
IF UNIT_PRICE_ZERO then PRICE_PER_UNIT
ELSE AMOUNT/CALL_MINS en 20 10/4 COMPRESS

/DERIVEDFIELD DEL "|"

/OUTFILE $OUT_FILE OVERWRITE

/REFORMAT
P_NUMBER,B_MONTH,B_YEAR,D_MONTH,D_YEAR,C_NUMBER,CALL_MINS,PRICE_PER_UNIT,DEL,AMOUNT

/STATISTICS /* Sends SyncSort */
/END
endofsort

Here i want to maintain 4 precision of unit price field.
COMPRESS is used to compress extra spaces but it also compress zeros of precision.

Can anyone suggest how to get required output.

Last edited by MadeInGermany; 03-16-2018 at 04:11 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple arithmetic operation

I have no idea why I can't get this to work, if anybody can help i would appreciate it. #!/bin/bash x=`cat counter.txt | wc -l` y= '$x / 7' printf "%d People have visited this page" $y :confused: (2 Replies)
Discussion started by: paladyn_2002
2 Replies

2. Shell Programming and Scripting

Help with arithmetic operation

I am using egrep to extract numbers from a file and storing them as variables in a script. But I am not able to do any arithmetic operations on the variables using "expr" because it stores them as char and not integers. Here is my code and the error I get. Any help will be appreciated. #!/bin/sh... (3 Replies)
Discussion started by: emjayshaikh
3 Replies

3. UNIX for Dummies Questions & Answers

arithmetic operation on two columns

Hi, All, I have a file, its content is as follows: 100 150 120 135 140 170 I want to insert a column, its content is determined by the difference between the two values in the same line, if the difference is less than 20, the new value is 1, otherwise is 0. after the operation, the... (1 Reply)
Discussion started by: Jenny.palmy
1 Replies

4. Shell Programming and Scripting

How to perform arithmetic operation on date

Hi all, I would appreciate if anyone knows how to perform adding to date. As for normal date, i can easily plus with any number. But when it comes to month end say for example 28 Jun, i need to perform a plus with number 3, it will not return 1 Jul. Thanks in advance for your help. (4 Replies)
Discussion started by: agathaeleanor
4 Replies

5. Shell Programming and Scripting

Arithmetic operation with awk

I have output like following in a file usmtnz-dinfsi19 72 71 38 1199 1199 0.8 19:23:58 usmtnz-dinfsi19 72 71 38 1199 1199 0.8 19:24:04 (9 Replies)
Discussion started by: fugitive
9 Replies

6. Shell Programming and Scripting

Arithmetic operation between columns using loop variable

Hi I have a file with 3 columns. say, infile: 1 50 68 34 3 23 23 4 56 ------- ------- I want to generate n files from this file using a loop so that 1st column in output file is (column1 of infile/(2*n+2.561)) I am doing like this: for ((i=1; i<=3; i++)) do a=`echo... (3 Replies)
Discussion started by: Surabhi_so_mh
3 Replies

7. Shell Programming and Scripting

floating point arithmetic operation error

I am writing a script in zsh shell, it fetchs a number from a file using the awk command, store it as a variable, which in my case is a small number 0.62000. I want to change this number by multiplying it by 1000 to become 620.0 using the command in the script var2=$((var1*1000)) trouble is... (2 Replies)
Discussion started by: piynik
2 Replies

8. UNIX for Dummies Questions & Answers

Basic arithmetic operation with awk?

input: Name|Operation rec_10|1+2+2- Output: rec_10|1 Basically I am trying to calculate the result of "the path" in $3 where the operators follow the number and not preceding them like we normally do: rec_10: +1+2-2=1 But I realise (I am sure there is a good reason for that) that awk... (7 Replies)
Discussion started by: beca123456
7 Replies

9. Shell Programming and Scripting

Arithmetic operation in variable

Hi, Here is the script i try to perform arithmetic operation in two variables . git branch -r | while read brname ; do REV_COMMITS=`git rev-list --count $brname` echo "$brname has $REV_COMMITS" (( TOTAL = TOTAL + REV_COMMITS )) echo "in loop" $TOTAL done echo "total is " $TOTAL ... (3 Replies)
Discussion started by: greet_sed
3 Replies

10. Shell Programming and Scripting

Using awk to do arithmetic operation

Hi, I've this following text file FileVersion = 1.03 Filetype = meteo_on_curvilinear_grid TIME = 0 hours since 2016-10-03 12:00:00 +00:00 -6.855 -6.828 -6.801 -6.774 -6.747 -6.719 -6.691 -6.663 -6.634 -6.606 -6.577 -6.548 -6.519 -6.489 TIME = 0 hours since... (2 Replies)
Discussion started by: xisan
2 Replies
OGGCUT(1)							   User Manuals 							 OGGCUT(1)

NAME
oggCut - extracts parts of an ogg file (.ogv, .ogg and .oga) SYNOPSIS
oggCut [options] inputfile outputfile DESCRIPTION
oggCut creates a new ogg file named outputfile as a subpart of the original file named inputfile oggCut is able to cut video (theora) only files, audio (vorbis) only files or files with both video and audio streams. The start and end time for the cut area must be given in milliseconds with the options -s and -e. As a video stream consists of I-frames (which are full pictures) and P-frames (which are delta pictures to the leading I-frame) the oggCut algorithm searches for the first I-frame. If a video file would start with a p-frame, the player is not able to interpret this picture, as the leading I-frame (on where it is based) is not available. oggCut starts the I-frame search at the start time given by the -s option. So expect a shorter video time than the calculated seconds for the new file. oggCut does not do any reencoding, therefore the output quality is completely the same as from the input file. For those involved into the ogg container format: The file is cut on packet basis, not on page basis. There is another tool called oggCut out in the internet with a different synopis. This one has not been written by the author of this tool you are actually using. OPTIONS
-s Cut start position in ms. If the input file is a video file, the cut area starts with the next keyframe found. Default: 0 Example: -s 5000 -l Length of the cut area in ms. If -e is also given, the length is ignored. Example: -l 10000 -e Cut end position in ms. If -l is also used, the end position is prefered. If the end position is set to -1, the end of the stream is assumed. Default: -1 Example: -e 20000 EXAMPLE
oggCut -s 1000 -e 21000 myVideo.ogv myOutput.ogv Creates a new video called myOutput.ogv from the video myVideo.ogv starting after 1 second ending after 21 seconds AUTHOR
Joern Seger <yorn at gmx dot net> SEE ALSO
oggCat(1), oggJoin(1), oggSplit(1), oggTranscode(1), oggSlideshow(1), oggThumb(1), oggSilence(1) Linux JAN 2010 OGGCUT(1)
All times are GMT -4. The time now is 12:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy