Sponsored Content
Full Discussion: Remove duplicate records
Top Forums Shell Programming and Scripting Remove duplicate records Post 302848751 by reignangel2003 on Friday 30th of August 2013 03:04:55 AM
Old 08-30-2013
am using bash shell below is just the part of the code i am using. the script needs a parameter for it to run.

Code:
Infile=$1
NotFinalOutFile=`echo $Infile | awk -F '.' '{print $1}'`

for files in `echo $Infile`
do
   sed 's/[ \t]*$//' $files | \
   sed 's/^$/)\n/' | egrep -vw 'Name|-' | \
   sed -e 's/desc/CREATE TABLE/;/CREATE / a\(' | \
   awk '{
         sub(/^\)/,"&;");                                       # Replace  ")" with ");"
         s=($0~/^[A-Z]/&& a~/^[A-Z]/ && !/"^CREATE "/)?",":"";  # IF this line and previous line start with "A-Z" and not "CREATE" set "s" to "," else set it to ""
         printf s"\n%s",                                        # Print this line "$0" using "s" as formating pluss new line
         a=$0}                                                      # Set a=this line
   END {
         print ""}'                                             # Print a new line
done >> $NotFinalOutFile.dat

---------- Post updated at 03:01 PM ---------- Previous update was at 02:48 PM ----------

actually, the script above just creates the create table statement.

---------- Post updated at 03:04 PM ---------- Previous update was at 03:01 PM ----------

below is the sample input file for the script:

Code:
desc a
Name         Null     Type
------------ -------- ------------
TRIAL_CLIENT NOT NULL VARCHAR2(60)
TRIAL_FUND   NOT NULL VARCHAR2(60)
LOCAL_ACC_NO NOT NULL VARCHAR2(60)
TRIAL_BROKER NOT NULL VARCHAR2(12)
CORR_ACC_NO  NOT NULL NUMBER(10)
CURRENCY     NOT NULL VARCHAR2(3)
VALUE_DATE   NOT NULL DATE

desc b
Name                      Null     Type
------------------------- -------- ------------
TRIAL_CLIENT              NOT NULL VARCHAR2(60)
TRIAL_FUND                NOT NULL VARCHAR2(60)
LOCAL_ACC_NO              NOT NULL VARCHAR2(60)
TRIAL_BROKER              NOT NULL VARCHAR2(12)
CORR_ACC_NO               NOT NULL NUMBER(10)
CURRENCY                  NOT NULL VARCHAR2(3)
AS_OF_DATE                NOT NULL DATE
SUM_OUR_CASH_TXNS                  NUMBER
SUM_OUR_POSITIONS                  NUMBER
COUNT_OUR_TRANSACTIONS             NUMBER
SUM_OUR_CASH_BALS                  NUMBER
SUM_OUR_UNREAL_BALS                NUMBER
SUM_BROKER_CASH_TXNS               NUMBER
SUM_BROKER_POSITIONS               NUMBER
COUNT_BROKER_TRANSACTIONS          NUMBER
SUM_BROKER_CASH_BALS               NUMBER
SUM_BROKER_UNREAL_BALS             NUMBER
SUM_UNSETT_INT                     NUMBER
SUM_OPEN_FWDS                      NUMBER
WO_AMT                             NUMBER

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Records Duplicate

Hi Everyone, I have a flat file of 1000 unique records like following : For eg Andy,Flower,201-987-0000,12/23/01 Andrew,Smith,101-387-3400,11/12/01 Ani,Ross,401-757-8640,10/4/01 Rich,Finny,245-308-0000,2/27/06 Craig,Ford,842-094-8740,1/3/04 . . . . . . Now I want to duplicate... (9 Replies)
Discussion started by: ganesh123
9 Replies

2. Shell Programming and Scripting

Remove all instances of duplicate records from the file

Hi experts, I am new to scripting. I have a requirement as below. File1: A|123|NAME1 A|123|NAME2 B|123|NAME3 File2: C|123|NAME4 C|123|NAME5 D|123|NAME6 1) I have 2 merge both the files. 2) need to do a sort ( key fields are first and second field) 3) remove all the instances... (3 Replies)
Discussion started by: vukkusila
3 Replies

3. Solaris

How to remove duplicate records with out sort

Can any one give me command How to delete duplicate records with out sort. Suppose if the records like below: 345,bcd,789 123,abc,456 234,abc,456 712,bcd,789 out tput should be 345,bcd,789 123,abc,456 Key for the records is 2nd and 3rd fields.fields are seperated by colon(,). (2 Replies)
Discussion started by: svenkatareddy
2 Replies

4. Shell Programming and Scripting

How to remove duplicate records with out sort

Can any one give me command How to delete duplicate records with out sort. Suppose if the records like below: 345,bcd,789 123,abc,456 234,abc,456 712,bcd,789 out tput should be 345,bcd,789 123,abc,456 Key for the records is 2nd and 3rd fields.fields are seperated by colon(,). (19 Replies)
Discussion started by: svenkatareddy
19 Replies

5. Shell Programming and Scripting

Remove duplicate records

I want to remove the records based on duplicate. I want to remove if two or more records exists with combination fields. Those records should not come once also file abc.txt ABC;123;XYB;HELLO; ABC;123;HKL;HELLO; CDE;123;LLKJ;HELLO; ABC;123;LSDK;HELLO; CDF;344;SLK;TEST key fields are... (7 Replies)
Discussion started by: svenkatareddy
7 Replies

6. Shell Programming and Scripting

Remove Duplicate Records

Hi frinds, Need your help. item , color ,desc ==== ======= ==== 1,red ,abc 1,red , a b c 2,blue,x 3,black,y 4,brown,xv 4,brown,x v 4,brown, x v I have to elemnet the duplicate rows on the basis of item. the final out put will be 1,red ,abc (6 Replies)
Discussion started by: imipsita.rath
6 Replies

7. Shell Programming and Scripting

Remove somewhat Duplicate records from a flat file

I have a flat file that contains records similar to the following two lines; 1984/11/08 7 700000 123456789 2 1984/11/08 1941/05/19 7 700000 123456789 2 The 123456789 2 represents an account number, this is how I identify the duplicate record. The ### signs represent... (4 Replies)
Discussion started by: jolney
4 Replies

8. UNIX for Dummies Questions & Answers

Need to keep duplicate records

Consider my input is 10 10 20 then, uniq -u will give 20 and uniq -dwill return 10. But i need the output as , 10 10 How we can achieve this? Thanks (4 Replies)
Discussion started by: pandeesh
4 Replies

9. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

10. Shell Programming and Scripting

Duplicate records

Gents, Please give a help file --BAD STATUS NOT RESHOOTED-- *** VP 41255/51341 in sw 2973 *** VP 41679/51521 in sw 2973 *** VP 41687/51653 in sw 2973 *** VP 41719/51629 in sw 2976 --BAD COG NOT RESHOOTED-- *** VP 41689/51497 in sw 2974 *** VP 41699/51677 in sw 2974 *** VP... (18 Replies)
Discussion started by: jiam912
18 Replies
SORTBIB(1)						      General Commands Manual							SORTBIB(1)

NAME
sortbib - sort bibliographic database SYNOPSIS
sortbib [ -sKEYS ] database ... DESCRIPTION
Sortbib sorts files of records containing refer key-letters by user-specified keys. Records may be separated by blank lines, or by .[ and .] delimiters, but the two styles may not be mixed together. This program reads through each database and pulls out key fields, which are sorted separately. The sorted key fields contain the file pointer, byte offset, and length of corresponding records. These records are delivered using disk seeks and reads, so sortbib may not be used in a pipeline to read standard input. By default, sortbib alphabetizes by the first %A and the %D fields, which contain the senior author and date. The -s option is used to specify new KEYS. For instance, -sATD will sort by author, title, and date, while -sA+D will sort by all authors, and date. Sort keys past the fourth are not meaningful. No more than 16 databases may be sorted together at one time. Records longer than 4096 characters will be truncated. Sortbib sorts on the last word on the %A line, which is assumed to be the author's last name. A word in the final position, such as ``jr.'' or ``ed.'', will be ignored if the name beforehand ends with a comma. Authors with two-word last names or unusual constructions can be sorted correctly by using the nroff convention ``'' in place of a blank. A %Q field is considered to be the same as %A, except sorting begins with the first, not the last, word. Sortbib sorts on the last word of the %D line, usually the year. It also ignores lead- ing articles (like ``A'' or ``The'') when sorting by titles in the %T or %J fields; it will ignore articles of any modern European lan- guage. If a sort-significant field is absent from a record, sortbib places that record before other records containing that field. SEE ALSO
refer(1), addbib(1), roffbib(1), indxbib(1), lookbib(1) AUTHORS
Greg Shenaut, Bill Tuthill BUGS
Records with missing author fields should probably be sorted by title. 4.2 Berkeley Distribution April 29, 1985 SORTBIB(1)
All times are GMT -4. The time now is 12:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy