Calculation from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculation from a file
# 1  
Old 10-05-2011
Calculation from a file

Hi ,

I have a file with below format
Code:
6/1/200618:00:011348797339524635352499218493964052971
6/1/200617:00:011348672070311735349025833693964052971
6/1/200616:00:011348546711070035345679259193964052971

I want a output as below
Code:
6/1/200618:00:011348797339524635352499218493964052971
2.7727361896/1/200617:00:0113486720703117353490258336
939640529712.6695873836/1/200616:00:0113485467110700
353456792591939640529712.692496286

where last colume's (G) calculation is (((D1-D2)+(E1-E2))/(C1-C2))*100

Thanks

---------- Post updated at 10:57 PM ---------- Previous update was at 09:30 PM ----------

Pasting the input file in proper format

Code:
10/04/2011 00:02:33,174593188263854110,44953959474715628
10/04/2011 00:01:32,174591070726814355,44953323503613008
10/04/2011 00:00:01,174587935555599289,44952416464862080

need to calculate
((44953959474715628-44953323503613008)/(174593188263854110-174591070726814355) * 100 as so on

Last edited by radoulov; 10-05-2011 at 06:09 PM.. Reason: and we want you to use code tags!
# 2  
Old 10-05-2011
where is the date E1, E2 from?

Code:
awk -F, '{print $0 FS (D1-$3)/(C1-$2)*100;D1=$3;C1=$2}' infile

10/04/2011 00:02:33,174593188263854110,44953959474715628,25.7478
10/04/2011 00:01:32,174591070726814355,44953323503613008,30.0335
10/04/2011 00:00:01,174587935555599289,44952416464862080,28.9311

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk percentage calculation from a file

i have a file say test with the below mentioned details Folder Name Total space Space used /test/test1 500.1GB 112.0 GB /test/test2 3.2 TB 5TB /test/test3 3TB 100GB i need to calculate percentage of each row based on total space and space used and copy... (9 Replies)
Discussion started by: venkitesh
9 Replies

2. Shell Programming and Scripting

Calculation

Hi, i have a large file like this: Contig1 1 5 Contig1 2 4 Contig1 3 3 Contig1 4 5 Contig1 5 3 Contig1 6 4 Contig2 1 3 Contig2 2 7 Contig2 3 2 Contig2 4 9 Contig2 5 10 Contig2 6 3 Contig2 7 7 Contig2 8 2 Contig2 9 7 Contig2 10 5 contig1 2 4 contig1 3 3 contig1 4 5 (3 Replies)
Discussion started by: the_simpsons
3 Replies

3. Shell Programming and Scripting

VG calculation in GB

for i in `lsvg` do echo "VG Name:" $i echo "Total VG Size:" lsvg $i |grep "TOTAL PPs:" |awk '{print $7}' | cut -c2- echo "Free VG Size:" lsvg $i |grep "FREE PPs:" | awk '{print $7}' | cut -c2- done The PP Sizes are in MB. I like to have the sizes in GB. Also, I like to have the... (14 Replies)
Discussion started by: Daniel Gate
14 Replies

4. Shell Programming and Scripting

How do I include the file being compared into calculation?

nawk -F, 'NR==FNR{file=FILENAME;a++;next} a{if(FILENAME~file)next;b++;} END{ for(i in a){if(a && !b){print "NEW: "i}} for(i in b){if(b)print i"\t\t"b}}' OFS=, 123.csv *.csv I need to include 123.csv into the equation for the total output currently it compares whatever is on 123.csv against... (27 Replies)
Discussion started by: llcooljatt
27 Replies

5. Shell Programming and Scripting

math calculation for a txt file

Hi All, I have a text file which is only one column. I want to multiply all these values in file1.txt by 0.01 and get the output.txt file1.txt 65 85 90 ... output.txt 0.65 0.85 0.90 ... Thanks. Please use code tags when posting data and code samples! (2 Replies)
Discussion started by: senayasma
2 Replies

6. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # F.ne: CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

7. Shell Programming and Scripting

calculation

Could someone till me what this calculation really means let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440 (4 Replies)
Discussion started by: freddie999
4 Replies

8. Shell Programming and Scripting

File Size calculation with AWK

Hello Friends, Im calculating file sizes with below AWK script. I do this before some spesific files are transferred. I run the script it works but after several running it stuck with a limit of 2147483647 (2 Gbytes -1 byte) and cant exceed this. Something is wrong and I can't proceed, would... (1 Reply)
Discussion started by: EAGL€
1 Replies

9. UNIX for Dummies Questions & Answers

calculation on a large file

Trying to do some simple maths on a large file. Excel works fine but I have 1 million entries: If the difference between a number in column 2 and the one above it is more than 100 the insert a new line 8 4001 4100 8 4101 4200 8 4201 4300 8 15901 16000 8 15910 ... (1 Reply)
Discussion started by: dr_sabz
1 Replies

10. Shell Programming and Scripting

calculation

Hi, I am in ksh88 I am trying to get the result of the calculation using 3 variables: TOTAL CAPACITY and get the following error: $DB_CAPACITY=(( $DB_SIZE * 100 / $TOTAL )) ksh: syntax error: `((' unexpected I cannot figure out what am I doing wrong... Thanks for any help -A (2 Replies)
Discussion started by: aoussenko
2 Replies
Login or Register to Ask a Question