Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I need help on filtering data in a file. There are 2 files. The 1st one contains the index numbers and a time. The time is in date + ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    6

    Filtering data in a file

    Hi,

    I need help on filtering data in a file. There are 2 files. The 1st one contains the index numbers and a time. The time is in date + time format. A sample of this file is like this. In this file, for each index number there's a single record.

    732008347|20090106153939
    616017186|20090106113041
    762163352|20090106081408
    842010597|20090106171854
    293848499|20090106171440

    The second file contains data for the index numbers in the 1st file. A sample is like this.

    732008347|20090106161420|5|63
    762163352|20090106215346|5|254
    842010597|20090106184608|1|1016
    732008347|20090106185429|1|254
    842010597|20090106184957|1|508
    842010597|20090106191403|1|508
    732008347|20090106191923|1|508

    The 2nd field in the 2nd file is also date & time. There may be more than one record for each index number in the 2nd file.

    I have to filter out the records from 2nd file, using the records in the 1st file. For each index number, i need to get the records where the time is later than the time in the record in the 1st file.

    It is something like this. The 2nd file contains transactions during the whole day. The 1st file contains a particular time for each index numer. I need to find the transactions which happened later than the time given in the 1st file from the 2nd file's records.

    I tried using a for loop. But as the 1st file has around 90000 records it's taking too much time. Can anyone please let me know how to do this without using a loop?

    Thanks a lot

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Use nawk or /usr/xpg4/bin/awk on Solaris:

    Code:
    awk -F\| 'NR == FNR {
      _[$1] = $2
      next
      }
    $1 in _ && $2 > _[$1]
    ' file1 file2

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    6
    It works

    Thank you very much.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...