Sponsored Content
Top Forums Shell Programming and Scripting Grab unique record from different files on a condition Post 302596535 by bartus11 on Tuesday 7th of February 2012 05:11:51 PM
Old 02-07-2012
Try:
Code:
#!/usr/bin/perl
$file1=shift;
$file2=shift;
open A,"$file1";
open B,"$file2";
while (chomp($line=<A>)){
  @temp=split / /,$line;
  $lowA{$temp[0]}{$.}=$temp[1];
  $highA{$temp[0]}{$.}=$temp[2];
}
while (chomp($line=<B>)){
  @temp=split / /,$line;
  $lowB{$temp[0]}{$.}=$temp[1];
  $highB{$temp[0]}{$.}=$temp[2];
}
for $iA (keys %lowA){
  for $jA (keys %{$lowA{$iA}}){
    for $iB (keys %{$lowB{$iA}}){
      if ($lowA{$iA}{$jA}>=$lowB{$iA}{$iB} && $lowA{$iA}{$jA}<=$highB{$iA}{$iB}){
        $elimA{$iA}{$jA}=1;
        $elimB{$iA}{$iB}=1;
      }
      if ($highA{$iA}{$jA}>=$lowB{$iA}{$iB} && $highA{$iA}{$jA}<=$highB{$iA}{$iB}){
        $elimA{$iA}{$jA}=1;
        $elimB{$iA}{$iB}=1;
      }
    }
  }
}
for $iB (keys %lowB){
  for $jB (keys %{$lowB{$iB}}){
    for $iA (keys %{$lowA{$iB}}){
      if ($lowB{$iB}{$jB}>=$lowA{$iB}{$iA} && $lowB{$iB}{$jB}<=$highA{$iB}{$iA}){
        $elimB{$iB}{$jB}=1;
        $elimA{$iB}{$iA}=1;
      }
      if ($highB{$iB}{$jB}>=$lowA{$iB}{$iA} && $highB{$iB}{$jB}<=$highA{$iB}{$iA}){
        $elimB{$iB}{$jB}=1;
        $elimA{$iB}{$iA}=1;
      }
    }
  }
}
for $i (keys %lowA){
  for $j (keys %{$lowA{$i}}){
    print "$i $lowA{$i}{$j} $highA{$i}{$j} $file1\n" if $elimA{$i}{$j}!=1;
  }
}
for $i (keys %lowB){
  for $j (keys %{$lowB{$i}}){
    print "$i $lowB{$i}{$j} $highB{$i}{$j} $file2\n" if $elimB{$i}{$j}!=1;
  }
}

Run it as: ./script.pl 1.txt 2.txt
This User Gave Thanks to bartus11 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh scripting: Extract 1 most recent record for unique key

I'm loading multiple delimited files into an Oracle DB using sqlldr on Unix. I would like to get only the most recent record per each unique key. There may be multiple updates for each key, but I only want the most recent one. There is a date column in my delimited files, so I'm using cat to... (2 Replies)
Discussion started by: OPTIMUS_prime
2 Replies

2. Shell Programming and Scripting

Managing sequence to make unique record

Hi Everyone, Using shell script i am getting final file as attached below. In this 4th column value should be unique using any sequence. for instance I've 1_13020_SSGM which is appearing 6 times in file and i should change it like 1_13020_SSGM_1,1_13020_SSGM_2,....1_13020_SSGM_6. Can someone... (4 Replies)
Discussion started by: gehlnar
4 Replies

3. Shell Programming and Scripting

Help with File processing - Adding predefined text to particular record based on condition

I am generating a output: Name Count_1 Count_2 abc 12 12 def 15 14 ghi 16 16 jkl 18 18 mno 7 5 I am sending the output in html email, I want to add the code: <font color="red"> NAME COLUMN record </font> for the Name... (8 Replies)
Discussion started by: karumudi7
8 Replies

4. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

5. Shell Programming and Scripting

compare 2 files and return unique lines in each file (based on condition)

hi my problem is little complicated one. i have 2 files which appear like this file 1 abbsss:aa:22:34:as akl abc 1234 mkilll:as:ss:23:qs asc abc 0987 mlopii:cd:wq:24:as asd abc 7866 file2 lkoaa:as:24:32:sa alk abc 3245 lkmo:as:34:43:qs qsa abc 0987 kloia:ds:45:56:sa acq abc 7805 i... (5 Replies)
Discussion started by: anurupa777
5 Replies

6. Shell Programming and Scripting

Replace string, grab files, rename and move

Hello there! I'm having a lot of trouble writing a script. The script is supposed to: 1) Find all files with the name "Object.mtl" within each folder in the directory: /Users/username/Desktop/convert/Objects 2) Search and replace the string ".bmp" with ".tif" (without the quotations) 3)... (1 Reply)
Discussion started by: Blue Solo
1 Replies

7. Shell Programming and Scripting

Output first unique record in csv file

Hi, I have to output a new csv file from an input csv file with first unique value in the first column. input csv file color product id status green 102 pass yellow 201 hold yellow 202 keep green 101 ok green 103 hold yellow 203 ... (5 Replies)
Discussion started by: Chris LAU
5 Replies

8. UNIX for Dummies Questions & Answers

FTP mget will only grab files not folders

Hey All, first post :rolleyes: So I am writting a script to pull down files from an ftp that will be called from a bat file on windows. This seems pretty straight forward, and grabs all of the "files" in the cd location, but I am running into some permission issue that will not allow me to... (1 Reply)
Discussion started by: mpatton
1 Replies

9. UNIX for Beginners Questions & Answers

Remove footer record in specific condition

Hi Experts, we have a requirement , need your help to remove the footer record in the file. Input file : 1011070375,,21,,NG,NG,asdfsfadf,1011,,30/09/2017,ACI,USD,,0.28,,,,,,,,,,,, 1011070381,,21,,NG,NG,sgfseasdf,1011,,30/09/2017,ACI,GBP,,0.22,,,,,,,,,,,,... (6 Replies)
Discussion started by: KK230689
6 Replies

10. Shell Programming and Scripting

CSV File:Filter duplicate records from column1 & another column having unique record

Hi Experts, I have csv file with 30, 40 columns Pasting just 2 column for problem description. Need to print error if below combination is not present in file check for column-1 (DocumentNumber) and filter columns where value in DocumentNumber field is same. For all such rows, the field... (7 Replies)
Discussion started by: as7951
7 Replies
machid(1)						      General Commands Manual							 machid(1)

NAME
machid: hp9000s200, hp9000s300, hp9000s400, hp9000s500, hp9000s700, hp9000s800, hp-mc680x0, hp-pa, pdp11, u370, u3b, u3b10, u3b2, u3b5, vax - provide truth value about processor type SYNOPSIS
DESCRIPTION
The following commands return a true value (exit code 0) if the a processor type matches the command name. Otherwise a false value (exit code nonzero) is returned. These commands are commonly used within makefiles and shell procedures to improve portability of applications (see make(1)). +-----------+-------------------------++--------+--------------------------+ |Command | True for ||Command | True for | +-----------+-------------------------++--------+--------------------------+ |hp9000s200 | Series 200 ||pdp11 | PDP-11/45 or PDP-11/70 | |hp9000s300 | Series 300 ||u3b | 3B20 computer | |hp9000s400 | Series 400 ||u3b2 | 3B2 computer | |hp9000s500 | Series 500 ||u3b5 | 3B5 computer | |hp9000s700 | Series 700 ||u3b10 | 3B10 computer | |hp9000s800 | Series 800 or 700 ||u370 | IBM System/370 computer | |hp-mc680x0 | Series 200, 300, or 400 ||vax | VAX-11/750 or VAX-11/780 | |hp-pa | Series 700 or 800 || | | +-----------+-------------------------++--------+--------------------------+ EXAMPLES
Given a shell script that must behave differently when run on an HP 9000 Series 700 or 800 system, select the correct code segment to be executed: WARNINGS
always returns true on both Series 800 and Series 700 systems. Therefore, when using this command in scripts to determine hardware type, always use both and in the appropriate sequence to ensure correct results (see machid(1) will no longer provide support for future machines beyond the Series 800 and Series 700 systems. Decisions should be based on the hardware and software configuration information returned by getconf(1). SEE ALSO
getconf(1), make(1), sh(1), test(1), true(1). machid(1)
All times are GMT -4. The time now is 10:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy