Help with formula in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with formula in a script
# 1  
Old 08-15-2007
Help with formula in a script

I need some help. I been doing system admin for the last several years and gotten very rusty on scripting. I need to write a script that will take a log entry and do math using two columns of data to create a new column. I am taking the column(#2) that contains the time and the column(#5) that contains transaction milliseconds and subracting that column for the time column to create a new column in the file. I am butting my head against my screen trying to remember who to do it. Here is an example of my log entry.

20070401 004639826 decode 10578 2770 2.77 00:46:37 29.728125 10.732
17509

So to make it easier to understand if I didn't above(up for about 20 hours working on a project so I might be a little fuzzy, LOL)
I want something that does this:
004639826 - 2770 = 004637056
And overwrites the 004637056 to column 8 to have the following output:
20070401 004639826 decode 10578 2770 2.77 004637056 29.728125 10.732
17509


I much appreciate any help that you can provide.


Thanks in Advance.

Scott

Last edited by scottzx7rr; 08-15-2007 at 03:49 AM..
# 2  
Old 08-15-2007
try awk

Hi, i am a newer in shell script. Since you have been dba for a long time. I think you should be a expert. But any way, follow is my suggestion:
Code:
awk '{$7=$2-$5
for (i=1;i<NF;i++)
printf("%s",$i)
}' filename

Hope it is useful for you!
# 3  
Old 08-15-2007
$7 should have 2 leading 0's according to requirement
Code:
awk '{$7=$2-$5 
len="%0"length($2)"d"
$7=sprintf(len,$7)
$1=$1
print
}' "file"

output:
Code:
# ./test.sh
20070401 004639826 decode 10578 2770 2.77 004637056 29.728125 10.732 17509

# 4  
Old 08-15-2007
That is what I needed. Thanks Guys. I appreciate your help! I was having a mind freeze. You work with Ciscos, f5s and basic unix for so long you forget the fun stuff. LOL I haven't had to get deep in a long time.

Yeah the column is always going to have 9 characters as it is HHMMSSMMM. I tested it on the log files and with 2 million records worked flawlessly. I appreciate the help greatly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Formula calculate scan rate

Hi There, Just curious here... If there formula to calculate scan rate on solaris? Thanks Edy (3 Replies)
Discussion started by: edydsuranta
3 Replies

2. Shell Programming and Scripting

A strange formula

Dear Masters, Kindly need your helps for this issue.. I face a formula as a picture... the input file is A DEPT Vp Vs rho VPperVS ------------------------ ------------ ------------ ------------ 700 151.9218 121.9269 ... (11 Replies)
Discussion started by: ipatah
11 Replies

3. Shell Programming and Scripting

Formula missing in excel after using perl

Hi all, I use "Spreadsheet::ParseExcel::SaveParser" to - read a existing excel file with : $Parser = Spreadsheet::ParseExcel::SaveParser->new(); $HeaderFile = $Parser->Parse("XLS_FILE_ACCESS"); - modify some values in somes cell with : $worksheet->AddCell($row_target,$col_max,... (3 Replies)
Discussion started by: Yom
3 Replies

4. Shell Programming and Scripting

formula missing in excel after using perl

Dear all, I got a template excel file which contains several worksheets. Each worksheet contains some formulas in the cells. I am using the perl script to read a CSV file and then put the data of CSV into template excel file(first worksheet) and then save it as new file name using ... (0 Replies)
Discussion started by: eldonlck
0 Replies

5. Shell Programming and Scripting

Convert Formula to Value

I'm new to Perl, but I need to use it to write into an excel spreadsheet. I want to copy the values of certain cells into a new sheet in the workbook. I'm unsure of how to do this because I don't know how to copy values instead of formulas. Note: by formula I mean '=SUM(A1,A2)' and by value I... (0 Replies)
Discussion started by: AgentSmith88
0 Replies

6. Shell Programming and Scripting

Formula to get combination… sum

Formula to get combination Lats say, I have 5 values ID Price 1 5 2 10 3 30 4 5 Resule with Possible combinations will be ID Price 1 5 2 10 3 30 4 5 1+1 10 1+2 15 1+3 35 1+4 10 (1 Reply)
Discussion started by: Amit.Sagpariya
1 Replies

7. Shell Programming and Scripting

how to create script for this formula?

Hello Unix gurus, Can anyone tell me the most efficient way to create script for the formula? Formula: Ans = 1 - ((Buffer pool data physical reads + Buffer pool xda physical reads + Buffer pool index physical reads + Buffer pool temporary data physical reads + Buffer pool temporary xda... (6 Replies)
Discussion started by: Rahulpict
6 Replies

8. UNIX for Dummies Questions & Answers

Formula help

The formula below will calculate a distance in miles between 2 points in excel. Can some put it to work in unix? Lat = 43.335 Lon1 = -70.9884 Lat2 = 43.4829 Lon2 = -71.246 distance... (8 Replies)
Discussion started by: bobo
8 Replies

9. Solaris

formula to get the swap space on a machine

Hello there are different opinions on how to get the swap space on Solaris. some say: swap -s and the space= used + available others say swap -l (donno how they get the swap size) other say 'top' command others say using format command (in print sub-command) Could you please advise on... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

10. UNIX for Advanced & Expert Users

Quadratic Formula Program

I have a question about the program I am making. I finished it, compiled it, and there were no errors. Now when I run it, the comand prompt comes up and there are just 1's and 0's that keep looping over and over again. The program is listed before. If anyone has any suggestions I would greatly... (2 Replies)
Discussion started by: zeek
2 Replies
Login or Register to Ask a Question