column value comparison in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting column value comparison in a file
# 1  
Old 12-13-2010
column value comparison in a file

Hi,

Can any one help with my below requirement.

i need to compare each line by line and in each line i have to compare some columns values with previous line column values in perl script.

Can any one help me........! its very urgent.

Thanks
# 2  
Old 12-13-2010
Please show sample input and desired output for us to get the exact idea about your problem.
R0H0N
# 3  
Old 12-13-2010
Please see my below sample file

M000001866|SN74LS147DR2|9.9|1.75|1.27|DUAL|70|0|5.25|4.75|5|33|9|
M000001866|SN74LS147DR2|9.9|1.75|1.27|DUAL|70|0|5.25|4.75|5|31|9|
M000005010|HCS283K/SAMPLE||||DUAL|||5.5|4.5|5|62|4|
M000005010|HCS283K/SAMPLE||||DUAL|||5.5|4.5|5|40|4|

in this if u see -f1 it has M000001866 in 1,2 lines and in the last but one column for the first line we hav 33 and in 2nd line we have 31

if this column has a different value compare to previous line same column it as show the flag as CHANGED at the end of the line.
# 4  
Old 12-13-2010
My first question is, does this file contain 2 entries for each id(e.g. M000001866)?? I mean is this file identical?

I m assuming the answer yes for this question. Also, I guess u have opened this file in your perl script and reading line by line.

Code:
open FF, "</path/file";
    my $lastid = "";
    my $lastvalue = 0;
    while (<FF>) {
        chomp $_;
        my ($id, $value) = (split /|/, $_)[0,11];
        if ($id eq $lastid) {
            my $diff = $value - $lastvalue;
            print "DIFF OF $id = [".$diff."]\n" if ($diff != 0);
        }
        $lastid = $id;
        $lastvalue = $value;
    }
close FF;

R0H0N
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Range Comparison Of Column Value in File1 with Other File

Hi, I have a file1 whose 17th column needs to be checked if it exists in between the values of column 2 & column 3 as mentioned in another file2. Output of the matched value to be put in separate file 3 & 4. File1: ... (10 Replies)
Discussion started by: siramitsharma
10 Replies

2. Shell Programming and Scripting

Need help in column comparison & adding extra line to files

Hi, I wanted to check whether the x,y,z coordinates of two files are equal or not. At times, when one file is converted to another suitable file extension , there are some chances that the data mismatch would happen during the conversion. In order to avoid the data misfit, i would like to... (6 Replies)
Discussion started by: b@l@ji
6 Replies

3. Shell Programming and Scripting

File Comparison: Print Lines not present in another file

Hi, I have fileA.txt like this. B01B02 D0011718 B01B03 D0012540 B01B04 D0006145 B01B05 D0004815 B01B06 D0012069 B01B07 D0004064 B01B08 D0011988 B01B09 D0012071 B01B10 D0005596 B01B11 D0011351 B01B12 D0004814 B01C01 D0011804 I want to compare this against another file (fileB.txt)... (3 Replies)
Discussion started by: genehunter
3 Replies

4. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

5. Shell Programming and Scripting

Help with file comparison

Hello, I am trying to compare 2 files and get only the new lines as output. Note that new lines can be anywhere in the file and not necessarily at the bottom of the file. I have made the following progress so far. /home/aa>cat old.txt 0001 732 A 0002 732 C 0005 732 D... (7 Replies)
Discussion started by: cartrider
7 Replies

6. Shell Programming and Scripting

awk column comparison big file

Hi all, I would like to compare a column in one file to a column in another file and when there is a match it prints the first column and the corresponding second column. Example File1 ABA ABC ABE ABF File 2 ABA 123 ABB 124 ABD 125 ABC 126 So what I would like printed to a... (6 Replies)
Discussion started by: pcg
6 Replies

7. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

8. Shell Programming and Scripting

Column comparison between two files: moved from another post

I have two files as follows: Pval.txt ID Pvalue 91500 0.004 91700 0.007 91800 0.12 91900 0.05 92000 0.99 Freq.txt ID Frequency 90000 56 91500 29 91600 78 91700 60 91800 77 91900 66 92000 70 92100 50 92200 60I need to compare 1st... (19 Replies)
Discussion started by: cs_novice
19 Replies

9. Shell Programming and Scripting

Looking for AWK Solution for column comparison in a single file

- I am looking for different kind of awk solution which I don't think is mentioned before in these forums. Number of rows in the file are fixed Their are two columns in file1.txt 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 I am looking for 3... (1 Reply)
Discussion started by: softwarekids23
1 Replies

10. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies
Login or Register to Ask a Question