Select unique records using key

  • Permalink
  • submit to reddit
  • Email
  • Follow


I need to select unique records from a file based on a key in the
file.  For example, the key field is in columns 1-6.

123456ABCD
123457ABCD
123456EFGH

Output file

123456ABCD
123457ABCD

I searched the websites to find some code I could reapply but had no
luck.  Can someone please share some code that would create this
output?
Thanks.
Sandy
0
Reply assum 8/10/2004 1:45:23 PM

See related articles to this posting

Sandy <assum.sr@pg.com> wrote:
> I need to select unique records from a file based on a key in the
> file.  For example, the key field is in columns 1-6.

> 123456ABCD
> 123457ABCD
> 123456EFGH

> Output file

> 123456ABCD
> 123457ABCD

> I searched the websites to find some code I could reapply but had no
> luck.  Can someone please share some code that would create this
> output?

Sorry, no code, but a simple combination of the 'sort' and 'uniq'
utilities should do the job perfectly well:

sort data_file | uniq -w 6
                                  Regards, Jens
-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de
0
Reply Jens 8/10/2004 2:12:53 PM

Sandy wrote:
> I need to select unique records from a file based on a key in the
> file.  For example, the key field is in columns 1-6.
> 
> 123456ABCD
> 123457ABCD
> 123456EFGH
> 
> Output file
> 
> 123456ABCD
> 123457ABCD
> 
> I searched the websites to find some code I could reapply but had no
> luck.  Can someone please share some code that would create this

perl -ne'print unless $seen{ substr $_, 0, 6 }++' yourfile



John
-- 
use Perl;
program
fulfillment
0
Reply John 8/10/2004 6:29:33 PM
comp.unix.programmer 10602 articles. 64 followers. Post

2 Replies
517 Views

Similar Articles

[PageSpeed] 45

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Highlight selection in a ListBox using arrow keys and enter for selection
Hi, I'm new to Perl and I appreciate any help I can get. I'm simply at loss when it comes to highlight an entry in a ListBox when a selection has been made by using arrow keys and enter. When using (mouse)Button-1 highlighting works fine. The listbox gets properly populated and selection can be made both from mouse button-1 and the enter key (positioned by the arrow keys). I assume I need some gizmo code in the sub which is called from the enter key binding. This is simply something I don't manage to solve by myself. Here are some code snippets: # ListBox declarat...

Selecting Unique Record
I have a stored procedure (below), that is suppose to get a Reg Number from a table, (Reg_Number), in such a way that every time the stored procedure is called, it will get a different reg number, even if the stored procedure is called simultaneously from two different places, However it is not working that way. If two different users access a function in there VB program at the same time, the two different users will get the same reg number. I have looked at the stored procedure, it looks foolproof, yet it is not working that way. Thanks in Advance, Laurence Nuttall Programmer Analyst II...

Unique key / record locking
Would appreciate ideas. I have a piece of code which generates a keyfield (sequence number) by reference to the previous record using a chain on descending key. However, multiple users will attempt to generate new keys, and will simply loop waiting for a succesful read and no lock. I'm concerned that heavy usage will write many messages to the joblog and will further slow the system down, alongside the read loop. Does anyone have a better suggestion for generating the next number in a sequence rather than by access to the actual previous record ? TIA for any ideas. Nick well, right ...

uniquely identify selected records in a table
Folks, >From what I've been able to gather from previous posts, I gather that the answer to my question is probably NO - but I'll ask just to make sure. I want to do the following: 1) Run a select query to find Record x. 2) Change the value in Field 1 of Record X from "Yesterday" to "Tomorrow" 3) Change the font color, font size, border, fill, anything associated with this record so that it can be uniquely identified by someone at a later date. It will be a table that will be accessed by lots of people with little or no Access experience - sort of like myself...

What wildcards should be used to select certain records?
Hello, I would like to perform an SQL procedure to select the records with their values of one column/variable having a certain pattern. One of the patterns is that the value is composed of 8 numbers followed by 1 letter, for instance, 12345678B. Anybody can give me some advice how to find these records with the pattern above? I searched through the SAS help but I could not find anything I need. I am wondering whether SAS can perform this procedure. I really appreciate any hints or suggestions. Thanks a lot! Laurie This one seems to work: data xx; input a $; cards; 1231347b asfafsgg 2...

Select Unique Distinct records for Column
Im trying to run a query that will pull distinct data not for the entire select query but for a single column. Here is my sql statement below. Why is it not working? It is probably something stupid. Thanks for your help in advance SELECT Count(MastrQualityTbl.[WORK NUMBER]) AS [TOTAL WORK RECEIVED], MastrQualityTbl.USERID, MastrQualityTbl.FIRSTNAME, MastrQualityTbl.LASTNAME, MastrQualityTbl.TEAM_NAME FROM MastrQualityTbl as c1 WHERE NOT EXISTS (SELECT MastrQualityTbl.[WORK NUMBER] from MastrQualityTbl WHERE MastrQualityTbl.[WORK NUMBER] = c1.WORK NUMBER) and WHERE (((MastrQualityTbl.DATE) Bet...

DTS Select using record position
Hi there, it has been a while since i have posted. I am in a situation where I am stumped. I am learning to build a dts package where I am connecting to a table in an AS400. This database is being maintained by an outsourced company and therefore I can't change the table structure or even ask them to. Anyway, this table currently has about 104,000 records. I am building a package to check it and pull out the most recent records and put them where they go in my SQL Server 2000 tables. The only way I can think of to get the most recent records is to use a global variable in the package...

Selecting duplicate records using a criteria
Hi, I have a dataset of patient visits. Using SAS, where there are many visits by the same patient (duplicate patid's), I want to identify the first visit and the one(s) that occur more than x days after the previous visit. I In other words, I only want to count visits that are x days apart (to rule out care for the same episode of illness). Example: patid dx admdate 8101 21 2/2/1999 8101 21 2/3/1999 8101 21 6/3/2003 In this case, I would want the records with admdates 2/2/1999 and 6/3/2003 only because they are > x (we'll say x=20) days apart. Anyone h...

creating view to select unique records
Hello All, I am unsure if similar question has already been posted to this group. If so please point me to the relevant post/group.. otherwise please read on... We are in the process of migrating our application from Sybase to Oracle. Basically for each table, we would do an bcp out of the table and load it into oracle via sqlldr. The source table has duplicate rows in it. However, we would not want to export those dupe rows to our oracle table. My intention is to create a view that would pick up only the unique records and I can bcp the data out of the view. I can create ...