![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Random number generation in ksh | mervin2006 | UNIX for Dummies Questions & Answers | 2 | 04-27-2007 02:02 AM |
| checking jump sequence number (part2) | happyv | Shell Programming and Scripting | 3 | 10-19-2006 06:03 AM |
| SQL Loader Auto Number Generation | vinoth_kumar | UNIX for Dummies Questions & Answers | 2 | 08-01-2006 08:40 AM |
| Random number generation | tej.buch | High Level Programming | 1 | 02-13-2006 10:07 AM |
| sequence number checking | nhatch | UNIX for Dummies Questions & Answers | 1 | 04-24-2003 02:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Sequence number generation on a key column
Hi Folks,
Can you help me with this issue: I have to generate the numbers say from 1001 for each record in a file based on a key field, the catch is the generated number should be unique based on key column. (EMP_NUMBER) Example: Input File: EMP_NUMBER EMP_NAME 8908 SMITH 8100 DAVID 8100 DAVID 8230 MARK 8240 GEORGE 8100 DAVID 8100 DAVID Output File: 8908 SMITH 1001 8100 DAVID 1002 8100 DAVID 1002 8230 MARK 1003 8240 GEORGE 1004 8100 DAVID 1005 8100 DAVID 1005 Thanks in advance. S ![]() |
|
||||
|
Hhuh? So adjacent DAVIDs should get the same number but different from another identical bunch of DAVIDs further down in the file? (And what cruel parents gave their children names in all uppercase??)
|
|
||||
|
I'm not sure if that was supposed to mean "no, sorry, the example was wrong; they're all the same DAVID" or "yes, sorry, the stuff about unique per key wasn't right actually" but assuming the former, how about
Code:
awk 'BEGIN { n = 1000 } { n++ if (k["$0"]++ == 0); print $0, $n}'
|
|
||||
|
It is actually later:
"yes, sorry, the stuff about unique per key wasn't right actually" Please find the request: I have to generate the numbers say from 1001 for each record in a file based on a key field (EMPLOYEE_NUMBER), we have to compare the current record (EMPLOYEE_NUMBER) with the previous records (EMPLOYEE_NUMBER), If different the seq. number has to be generated otherwise the number remains same for that record, Input File: EMP_NUMBER EMP_NAME 8908 SMITH 8100 DAVID 8100 DAVID 8230 MARK 8240 GEORGE 8100 DAVID 8100 DAVID Output File: Gen_Key 8908 SMITH 1001 8100 DAVID 1002 8100 DAVID 1002 8230 MARK 1003 8240 GEORGE 1004 8100 DAVID 1005 8100 DAVID 1005 Thanks S ![]() |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|