![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to extract duplicate rows | bobbygsk | Shell Programming and Scripting | 5 | 11-20-2008 11:31 AM |
| Remove duplicate rows of a file based on a value of a column | risk_sly | UNIX for Dummies Questions & Answers | 7 | 09-26-2008 07:26 AM |
| How to find all duplicate rows using awk | purvi | Shell Programming and Scripting | 7 | 08-21-2008 02:34 PM |
| how to delete duplicate rows in a file | vamshikrishnab | Shell Programming and Scripting | 5 | 06-18-2008 11:00 AM |
| duplicate rows in a file | infyanurag | Shell Programming and Scripting | 3 | 05-22-2008 01:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to get Duplicate rows in a file
Hi all,
I have written one shell script. The output file of this script is having sql output. In that file, I want to extract the rows which are having multiple entries(duplicate rows). For example, the output file will be like the following way. =============================================================== <SH12_MC30_CE_VS_NY_HIST_T> =============================================================== 397 44847 400 33653 401 46455 =============================================================== <SH12_MC30_CE_VS_NY_HIST_T_BKP> =============================================================== 397 44847 398 40107 399 39338 400 33653 In this output, I want numeric duplicate rows only. Suppose this file is having lines to separate the values, those lines also considered as duplicate rows. So I want only the out put from this file which is having more than one entry and which is related to numbers. Can anyone please tell me the command? Thanks in advance. Regards, Raghu. ![]() |
|
||||
|
Code:
cat file1 file2 | \
grep -v -e '^=' -e '^<' | \
awk '{ arr[$0]++} END{ for (i in arr) { if(arr[i]>1) { print i} }}' > newfile
|
|
||||
|
Hi Jim,
I could understand till second line of ur command. I couldn't understand the awk part. Becoz i dont know the awk features. But it is working. Thank you very much for that. 'awk' is so nice. Can you give any aother way to get it instead of awk. Thanks & Regards, Raghunadh. |
|
||||
|
Quote:
Code:
#!/bin/ksh
sort $1 > sortedfile
nawk '{ while (getline < sortedfile >0); array[n++]=$0; compare and remove non dup record here}'
|
|
||||
|
Hi vgersh99,
Thank you very much for ur reply. 'nawk' command id nice. But I dont know the 'awk' functionalities. So if I put this command in my script then I cant explain this command to anyone. So can you please provide me the command instead of 'awk' and 'nawk'. Thanks in advance, Regards, Raghu. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|