awk to subtract from values in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to subtract from values in file
Prev   Next
# 1  
Old 10-12-2015
awk to subtract from values in file

data.txt:

Code:
0,mq_conn_open_error,1444665949,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,733--734
0,mq_conn_open_error,1444666249,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,734--734
0,mq_conn_open_error,1444666549,735,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62107,0,734--735
0,mq_conn_open_error,1444666849,735,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62107,0,735--735
0,mq_conn_open_error,1444667149,735,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62107,0,735--735
0,mq_conn_open_error,1444667449,735,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62107,0,735--735
0,mq_conn_open_error,1444667749,736,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62192,0,735--736
0,mq_conn_open_error,1444668049,736,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62192,0,736--736
2,mq_conn_open_error,1444668349,742,/PROD/G/cicsitlp/sys/unikixmain.log,72K,mq_conn_open_error,62758,2,736--742
0,mq_conn_open_error,1444668649,742,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62758,0,742--742

I'm using the below code to get specific values:

Code:
gawk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, nodatetime_mq_conn_open_error  | gawk -F"," '/Oct 10 04.*2015,/,0 {print $10"-"$4"_"$11}'

when i run the above awk code, i get this:

Code:
0-1444665949_733--734
0-1444666249_734--734
0-1444666549_734--735
0-1444666849_735--735
0-1444667149_735--735
0-1444667449_735--735
0-1444667749_735--736
0-1444668049_736--736
2-1444668349_736--742
0-1444668649_742--742

What i need to do now, is, i want to be able to subtract the two numbers at the end so that when i run the awk code, it gives me the diference between the two numbers. something like this:

Code:
0-1444665949_1
0-1444666249_0
0-1444666549_1
0-1444666849_0
0-1444667149_0
0-1444667449_0
0-1444667749_1
0-1444668049_0
2-1444668349_6
0-1444668649_0

also, i want to be able to get the difference between values on two consecutive lines. for instance,

Code:
0,mq_conn_open_error,1444668049,736,/PROD/GAP/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62192,0,736--736
2,mq_conn_open_error,1444668349,742,/PROD/GAP/cicsitlp/sys/unikixmain.log,72K,mq_conn_open_error,62758,2,736--742

i want to have a separate awk command like the one above that will subtract the bolded value of a specific column in a log line from the same column in the line before it. so basically, the awk code would have to read the output given to it 2 lines at a time and do the substraction, then move on to the next two lines. hope this makes sense.

Last edited by SkySmart; 10-12-2015 at 02:29 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Subtract millisecond Timestamps with awk

Hello, am not able to subtract timestamps in milliseconds. I extract the timestamp as a string, and then try to subtract the two, but since it is a string, system just outputs 0 awk -F"," 'substr($1,0,13) - substr($2,0,013)' File where $1 and $2 are the timestamps in the format... (4 Replies)
Discussion started by: sidnow
4 Replies

2. Shell Programming and Scripting

awk to look up values in File 2 from File 1, & printingNth field of File1 based value of File2 $2

I have two files which are the output of a multiple choice vocab test (60 separate questions) from 104 people (there are some missing responses) and the question list. I have the item list in one file (File1) Item,Stimulus,Choice1,Choice2,Choice3,Choice4,Correct... (5 Replies)
Discussion started by: samonl
5 Replies

3. Programming

Subtract values based on records

Hi Guys, I am having below tables in oracle T1 ID F_TYPE F_AMT DATE_COL 1 F 6 11-Feb-16 1 D 2 11-Feb-16 1 D 2 11-Feb-16 1 F 6 11-Feb-16 1 F 2 12-Mar-16 1 D 3 12-Mar-16 1 F 4 10-Apr-16 1 F 4 11-Apr-16 1 D 1 11-Apr-16 T2 ID START_DATE END_DATE F_ID FLAG... (0 Replies)
Discussion started by: rohit_shinez
0 Replies

4. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

5. UNIX for Dummies Questions & Answers

awk to add/subtract an integer to/from each entry in columns?

---------- Post updated at 01:58 PM ---------- Previous update was at 01:48 PM ---------- For some reason my question is not getting printed. Here are the details: Greetings. I would like to add/subtact an integer to/from two columns of integers. I feel like this should be easy using awk... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

6. Shell Programming and Scripting

Add values in 2 columns and subtract from third

Hi All, I have a file with thousands of lines in the following format, where Field1=First 8 characters Field2-9-16 characters Field3=17-26 characters I need to add Field 1 and Field2 and subtract the result from Field 3. Field3=Field3 - (Field1 + Field2) 0012.00 0010.00 0001576.53... (4 Replies)
Discussion started by: nua7
4 Replies

7. Shell Programming and Scripting

Compare & subtract lines in files by column using awk.

I have two files with similar column pattern as given below : 2 sample lines from file1 are given below. 18 12630 . G T 49.97 . AC=2;AF=1.00;AN=2;DP=3;Dels=0.00;FS=0.000;HRun=0;HaplotypeScore=0.0000;MQ=60.00;MQ0=0;NDA=1;QD=16.66;SB=-0.01 GT:AD:DP:GQ:PL ... (2 Replies)
Discussion started by: vaibhavvsk
2 Replies

8. Shell Programming and Scripting

add and subtract specific row using awk

Hi Folks I have tried awk command to conditionally add or subtract value from specific row in a file. The test file looks like: # cat test.txt cont x y Max 0.3 0.9 Min 0.2 0.9 diff 0.1 0 # awk '{for (i=2; i <=NF; i++) if ($i== "0") $i=$i+0.2; print}' test.txt Output: cont... (1 Reply)
Discussion started by: dixits
1 Replies

9. Shell Programming and Scripting

Subtract field values

I've got a long logfile of the form network1:123:45:6789:01:234:56 network2:12:34:556:778:900:12 network3:... I've got a similar logfile from a week later with different values for each of the fields eg network1:130:50:6800:10:334:66 network2:18:40:600:800:999:20 network3:... ... (5 Replies)
Discussion started by: Yorkie99
5 Replies

10. Shell Programming and Scripting

AWK solution to subtract multiple columns of numbers

Hope somebody is happy. NR==1 { num_columns=split( $0, menuend ); next; } { split( $0, substrend ); for ( i=1; i<=NF; i++ ) { minuend -= substrend; } } END { print "Result:"; for ( i=1; i<=num_columns; i++ ) { printf(... (3 Replies)
Discussion started by: awkward
3 Replies
Login or Register to Ask a Question