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 10664 articles. 64 followers. Post

2 Replies
588 Views

Similar Articles

[PageSpeed] 57


  • 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 ...

How can I select a record in a subform using VB
Hi, I have a form displaying data with a related subform on a one to many basis. How can I move the current record to a particular record in the subform using VB? I have no problems doing this for records in the main form but cannot work out how to do it for records in the subform. Paul FindFirst the criteria you want to match in the RecordsetClone of the subform. This example assumes your subform has a field named "MyID", and you want to find the record where this is 9999. Dim strWhere As String Dim frm As Form Dim rs As DAO.Recordset strWhere = "MyID = 9999" Set fr...

Select Primary Key of Highest Record in each Group?
Ok... This was harder than I thought. The following query will get the "thing" from the row with the highest iVersion. SELECT vchThing, MAX(iVersion) AS iVersion FROM dbo.tmpThing GROUP BY vchThing However, if I need to get the primary key for the "thing" row, I am no longer successful... For example: SELECT pkThing, vchThing, MAX(iVersion) AS iVersion FROM dbo.tmpThing GROUP BY pkThing, vchThing Because you must include pkThing in the GROUP BY clause, it makes the unwanted records appear in the result set. Can anyone help with getti...

Combo Box Value Selection Unique to Record
How can I get the Value that I select using my Combo Box to be UNIQUE (to save to ONE record)to the respective Record that I am viewing on my Form? At present, when I select a Value from the Combo Box this Value displays on EACH of the 7441 records that I can view using my Form. I know its some small detail on my Combo Box properties that I am overlooking? Thanks for any ideas?! John On Wed, 23 Jul 2008 11:41:21 -0700 (PDT), zufie wrote: > How can I get the Value that I select using my Combo Box to be UNIQUE > (to save to ONE record)to the respective Record that I am viewing on &g...

User-selection of records, a unique problem. How to approach?
I have been working on a project that uses MS Access to get mutual fund performance and write it to a spreadsheet in a formatted manner. The user inputs the company name, the database looks at the company's 401k fund holdings and extracts the performance info and benchmark info for them. It writes out the information to a spreadsheet embedded on an Access form and simultaneously writes the same info to Excel. I also have logic built in that will compare the performance of the fund to its benchmarks and will highlight the row in the spreadsheet if if fails to beat one or both of its ben...

Select Unique Distinct records for Column #2
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...

How do I select (highlight) a record in a datasheet using VBA?
This simple stupid thing has me stumped! The cursor is on a record in a datasheet. How do I select that record (highlight) like I would if I clicked on the Record Selector using VBA. Regards. Barry --- This email from Barry Wright has been scanned using AVG 6.0 and is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.541 / Virus Database: 335 - Release Date: 11/14/03 Runcommand acCmdSelectRecord -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than all...

Multiple users, selecting unique record from table
Hi all, Come across a situation I cannot figure how to work out. Im relatively new to access but have looked around and tried everything to my knowledge. I've developed an application whereby users load up the database and open a form, this form issues them with work to complete, the work is completed and the next record is offered. There is a 'pot' of work that is loaded into a linked table every day, when new work is given to the agent the row is taken from the pot and stored in a local table (row in the pot then deleted) where over 10 minutes is regularly updated with outcome...

Re: Selecting duplicate records using a criteria
You should investigate the lag function. Here is pseudocode of what = you'd want (pseudocode only, not acual tested SAS code); data set1; set inputset; by patient_id; days_since_last_visit=3Dvisit_date - lag(visit_date); run; data set2; set set1; if days_since_last_visit=3D. or days_since_last_visit >=3D20; run; ----- Original Message -----=20 From: ljs=20 To: SAS-L@LISTSERV.UGA.EDU=20 Sent: Monday, March 10, 2008 1:47 PM Subject: Selecting duplicate records using a criteria Hi, I have a dataset of patient visits. Using SAS, where there are many ...

Use unique key for Sqlserver view for updates
I use an MsAccess frontend app that uses a 2 table view defined in Sql(2005). When i link the view manually I can say (and cache in Access) what field will be used as as primary key. This way I can update data in the view (in both underlying tables). In fact the same that is possible when I open the view via Sql management console. But... normally I don't link tables manually. But then Access can't get the information from Sqlserver what field can be used as a unique key. Is there a way to define such a thing in Sqlserver. Something like a 'hint' during the view definition?? Or...

Opening Selected Records in a Form Using Code
I would like to open selected (Filtered) records in a form. I currnetly have a custom menu but would like to only open certain records from i.e Button 1 will open Site 1 Button 2 will open Site 2 Etc I know this can be done using queries but I would rather use code for this as all the buttons open the same from from the same table. Can anyone help with this. Thanks Craig Look at the Help on the DoCmd.OpenForm -- the WhereCondition argument may do exactly what you want. You put a base query without criteria as the RecordSource of the Form, and the WhereCondition or Filter arguments are ...

Select and Update of records without being used by other users?
Hi All, I need to change a column value in several thousand records in a table and output a list of the record ids of the records I've updated into another table. The table, however, is being used by other users via a website, so I need to make certain that website requests don't touch on the records I'm selecting / updating. My attempt at a stored procedure goes thus: CREATE proc dbo.stp_mw_tag_irecords AS BEGIN TRANSACTION INSERT INTO tbl_tagged (recid) select top 100000 recid FROM tbl_active with(UPDLOCK) WHERE rectype='a' and used=0 UPDATE tbl_active set u...

Can I create unique index on selected records ?
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B Alvin Leader B Peter Member B Charlie Member What I want to do is to ensure that each team has one and only one Leader The unique index on Team+Role cannot achieve this purpose because there are many Member records. Functionally, what I want to do is to have unique index on Team+Role for those records with Role="Leader" Is there any spe...

Re: What wildcards should be used to select certain records?
This one seems to work: data xx; input a $; cards; 1231347b asfafsgg 2352676k 567h457p 3463465m ; proc sql; select * from xx having input(substr(a,1,7), ? best.) ne . and input(a, ? best.) = . ; a ---------- 1231347b 2352676k 3463465m Kind regards, Ya -----Original Message----- From: Laurie [mailto:laurieli_hua@YAHOO.COM] Sent: Wednesday, November 26, 2003 8:53 AM To: SAS-L@LISTSERV.UGA.EDU Subject: 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 patt...

Using check box in table to select records
Hello all I have the following PHP script to place records from my MySql db into a table. However I now wish users to beable to select the multiple records from the table and on clicking a button the selected records are stored to another table in my db. I have started by including a check box in the first column but dont know the code necessary to check all the row in the table and copy the records of those boxes thats ticked Can anyone help? Thanks Ian ***************************************** <table width="1022" border="2" align="left" cellpadding="0&qu...

Using a pop up menu for selecting records in find mode
I have a layout that is set as view as table (in order to sort ascending/decesending on field titles). One of the fields is a value list(pop up menu). Is it possible to, (in the find mode), set the value list field so that when you click on it the pop up menu displays then you can make a choice and then the find returns all the records based on the selection from the value list? Yes -- Al Lawrance British Columbia CANADA -------------------------------------- ajlawrance@shaw.ca http://www.members.shaw.ca/ajlawrance/ "Mark Lees" <mark_lees@byu.edu> wrote in message news:c4...