AWK - check column data

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support AWK - check column data
# 15  
Old 01-02-2010
Code:
#!/usr/bin/awk

BEGIN {
   col3[""]=0;
   col4[""]=0;
}

{
   if(col3[$3] <= 0){
       col3[$3] = 1;
       data3 = $3;
   }
   else {
      col3[$3]++;
      data3 = ($3-0.1*(col3[$3]-1)); 
   }

   if(col4[$4] <= 0) {
      col4[$4] = 1;
      data4 = $4;
   }
   else {
      col4[$4]++;
      data4 = ($4-0.1*(col4[$4]-1));
   }

   print $1 $2 data3 data4;

}

This is not tested..
# 16  
Old 01-03-2010
another approach:-

Code:
nawk 'a[$3$4]++ { $3 -= 0.1}1' test

but kindly radoulov in your solution
Code:
awk '($3 -= 0.1 * c[$3,$4]++)||1' infile

why you used multiplication instead of
Code:
awk '($3 -= 0.1 && c[$3,$4]++)||1' infile

# 17  
Old 01-03-2010

aaiaz:-

using multiplication and not && is for the subtraction value (amount) that we have to subtract after pattern repetition so you have to use
"*" not "&&"


by the way ...you code will not work proparly because each time you subtract
"0.1" although in the second pattern you have to subtract "0.2".

BR


SmilieSmilieSmilie
# 18  
Old 01-03-2010
Thanks man for the details ...I had understand now.

SmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get row data printed in column using awk?

Hi team, I have below sample file. $ cat sample dn: MSISDN=400512345677,dc=msisdn,ou=NPSD,serv=CSPS,ou=servCommonData,dc=stc structuralObjectClass: NphData objectClass: NphData objectClass: MSISDN entryDS: 0 nodeId: 35 createTimestamp: 20170216121047Z modifyTimestamp: 20170216121047Z... (3 Replies)
Discussion started by: shanul karim
3 Replies

2. Shell Programming and Scripting

Append data with substring of nth column fields using awk

Hi guys, I have problem to append new data at the end of each line of the files where it takes whole value of the nth column. My expected result i just want to take a specific value only. This new data is based on substring of 11th, 12th 13th column that has comma seperated value. My code: awk... (4 Replies)
Discussion started by: null7
4 Replies

3. UNIX for Dummies Questions & Answers

Using awk to find and use the maximum value in column of data

Dear Unix Gurus, I have a text file with multiple columns, for example, see sample.txt below 0 1 301 1 4 250 2 6 140 3 2 610 7 1 180I want to find the maximum in, say, column 3, normalise all the values to this maximum value (to 4 decimal places) and spit everything into a new... (2 Replies)
Discussion started by: tintin72
2 Replies

4. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

5. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

6. Shell Programming and Scripting

Printing another column using awk and input data

Hi, I have data of the following type, chr1 234 678 39 852 638 abcd 7895 chr1 526 326 33 887 965 kilj 5849 Now, I would like to have something like this chr1 234 678 39 852 638 abcd 7895 <a href="http://unix.com/thread=chr1:234-678">Link</a> chr1 526 326 33 887 965 kilj 5849 <a... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

7. Shell Programming and Scripting

Awk to add selected row column data

Looks at the most efficient way to add up the column of data based off of the rows. Random data Name-Number-ID Sarah-2.0-15 Bob-6.3-15 Sally-1.0-10 James-1.0-10 Scotty-10.7-15 So I would select all those who have ID = 15 and then add up total number read - p "Enter ID number" Num ... (3 Replies)
Discussion started by: Ironguru
3 Replies

8. Shell Programming and Scripting

Calculate data and make it into new column using awk

Hi everyone, just some simple question... i've been using a awk script to calculate my data... i have 3 files: file a1.txt: 2 3 4 5 3 4 file a2.txt: 4 5 6 7 8 (1 Reply)
Discussion started by: yat
1 Replies

9. Shell Programming and Scripting

two-column data to matrix in AWK

Howdy, I need to convert an association data matrix, currently in a two-column format, into a matrix with numbers indicating the number of associations. I've been looking around for AWK code in the list, but could not find anything. Here's an example of what I want to perform: original... (10 Replies)
Discussion started by: sramirez
10 Replies

10. Shell Programming and Scripting

How to check a column contain numeric or char data type ??

I have a file called clientname_filename.csv whose contents are like col1|col2|col3|col4| 510|abc|xxx|450| 510|abc11|yyy|350 510|pqr99|zzz| 670 512|222|439|110 Here i have check the contents of column for data type. i have a constraints that col1 always contain Numeric value column 2... (12 Replies)
Discussion started by: jambesh
12 Replies
Login or Register to Ask a Question