AWK - check column data

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support AWK - check column data
# 1  
Old 12-31-2009
AWK - check column data

Hi,

I have a data in a file .

Infile:

Code:
1 e 1.2  1.6 
5 f  2.3  3.6
3 g 1.2  2.6
6 i  2.3  3.6
8 o 1.2  3.6

output:

Code:
1 e 1.2  1.6 
5 f  2.3  3.6
3 g 1.1  2.6
6 i  2.2  3.5
8 o 1.0  3.4


In column #3 the first occurence of value is unchanged. the next same value occurence will be reduced by 0.1, and the next occurence will be reduced by 0.2,....it should continue according to the repeats.


Anybody has answer,

Thanks in advance
Vasanth

Last edited by radoulov; 12-31-2009 at 02:10 PM.. Reason: Please use code tags!
# 2  
Old 12-31-2009
Code:
awk '{ 
  for (i=2; ++i<=NF;)
    c[i,$i] = f[i,$i]++ ? c[i,$i] += 0.1 : 0 
  }
{ 
  for (i=2; ++i<=NF;) 
    $i = sprintf("%.1f",$i -= c[i,$i])
  }
 9' infile

# 3  
Old 12-31-2009
Hello ,
first of all Happy New year Smilie
try using hashes (err maybe in perl Smilie )
would come back to you .
Smilie
Regards.
# 4  
Old 12-31-2009
unexpected error

Dear radoulov,

I am getting error as ' unexpected.. please can u explain ur program...

Dear gaurav1086,

Thanks. same wishes to all...
Perl i can,t use. awk ans???

Thanks in advance,
Vasanth
# 5  
Old 12-31-2009
Quote:
Originally Posted by vasanth.vadalur
Dear radoulov,

I am getting error as ' unexpected.. please can u explain ur program...
[...]
What error do you get?
If you're on Solaris, you should use gawk (if available), nawk or /usr/xpg4/bin/awk.
# 6  
Old 12-31-2009
i am using cygwin.

Please, can u explain the above progam.

i will try my best to solve from my side..

Thanks
vasanth
# 7  
Old 12-31-2009
Quote:
Originally Posted by vasanth.vadalur
i am using cygwin.
[...]
It should work on Cygwin.
Please post the error.
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