Duplicate files and output list | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Duplicate files and output list

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-23-2012
jiam912's Unix or Linux Image
jiam912 jiam912 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 6 March 2015, 3:39 PM EST
Location: EEUU
Posts: 186
Thanks: 132
Thanked 0 Times in 0 Posts
Duplicate files and output list

Gents,

I have a file like this.


Code:
1 1
1 2
2 3
2 4
2 5
3 6
3 7
4 8
5 9

I would like to get something like it

Code:
1 1 2
2 3 4 5
3 6 7

Thanks in advance for your support Unix or Linux Image

Last edited by Scott; 10-23-2012 at 04:42 PM.. Reason: Code tags
Sponsored Links
    #2  
Old Unix and Linux 10-23-2012
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 7 November 2014, 10:50 AM EST
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts

Code:
awk '{a[$1]=a[$1]?a[$1]" "$2:$0}END{for(i in a){print a[i]}}' file

The Following User Says Thank You to pamu For This Useful Post:
jiam912 (10-23-2012)
Sponsored Links
    #3  
Old Unix and Linux 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 13 January 2015, 10:34 AM EST
Location: Houston, Texas, USA
Posts: 681
Thanks: 0
Thanked 206 Times in 198 Posts
also try:

Code:
awk '{a[$1]=a[$1] " " $2}END{for(i in a){print i a[i]}}' infile | sort

The Following User Says Thank You to rdrtx1 For This Useful Post:
jiam912 (10-23-2012)
    #4  
Old Unix and Linux 10-23-2012
jiam912's Unix or Linux Image
jiam912 jiam912 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 6 March 2015, 3:39 PM EST
Location: EEUU
Posts: 186
Thanks: 132
Thanked 0 Times in 0 Posts
Thansk a lot its works perfect...

---------- Post updated at 01:12 PM ---------- Previous update was at 01:01 PM ----------

Please, how I can get only the duplicate files

Code:
1 1 2
2 3 4 5
3 6 7


Last edited by Scott; 10-23-2012 at 04:42 PM.. Reason: Code tags
Sponsored Links
    #5  
Old Unix and Linux 10-23-2012
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 14 January 2015, 3:24 PM EST
Location: USA
Posts: 1,555
Thanks: 25
Thanked 150 Times in 142 Posts
Quote:
Originally Posted by jiam912 View Post
Please, how I can get only the duplicate files
1 1 2
2 3 4 5
3 6 7
What do you mean by this...
Sponsored Links
    #6  
Old Unix and Linux 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 13 January 2015, 10:34 AM EST
Location: Houston, Texas, USA
Posts: 681
Thanks: 0
Thanked 206 Times in 198 Posts
If you mean duplicate lines then use:

Code:
uniq -d

Sponsored Links
    #7  
Old Unix and Linux 10-23-2012
jiam912's Unix or Linux Image
jiam912 jiam912 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 6 March 2015, 3:39 PM EST
Location: EEUU
Posts: 186
Thanks: 132
Thanked 0 Times in 0 Posts
I found the solution like this

Code:
awk '{a[$1]=a[$1] " " $2}END{for(i in a){print i a[i]}}' infile | sort | awk '{if(NF>2)print $0}'

Thanks

Last edited by Scott; 10-23-2012 at 04:42 PM.. Reason: Code tags
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
list files command output kannan84 Shell Programming and Scripting 1 02-10-2012 12:34 AM
I need a script to find socials in files and output a list of those files NewSolarisAdmin Shell Programming and Scripting 1 02-19-2009 01:01 PM
Find duplicate value comparing 2 files and create an output ricky007 Shell Programming and Scripting 2 02-26-2008 04:57 PM
Dynamically redirect output to duplicate files ??? nsinha Shell Programming and Scripting 3 10-09-2007 08:04 AM
Removing duplicate files from list with different path vino Shell Programming and Scripting 10 05-12-2005 09:44 AM



All times are GMT -4. The time now is 12:22 AM.