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

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
jiam912's Avatar
jiam912 jiam912 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 3 September 2014, 4:43 PM EDT
Location: Ecuador
Posts: 140
Thanks: 99
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

Last edited by Scott; 10-23-2012 at 03:42 PM.. Reason: Code tags
Sponsored Links
    #2  
Old 10-23-2012
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 15 September 2014, 8:06 AM EDT
Posts: 1,649
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 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 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 10-23-2012
jiam912's Avatar
jiam912 jiam912 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 3 September 2014, 4:43 PM EDT
Location: Ecuador
Posts: 140
Thanks: 99
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 03:42 PM.. Reason: Code tags
Sponsored Links
    #5  
Old 10-23-2012
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 17 September 2014, 5:00 PM EDT
Location: USA
Posts: 1,462
Thanks: 19
Thanked 139 Times in 131 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 10-23-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
If you mean duplicate lines then use:

Code:
uniq -d

Sponsored Links
    #7  
Old 10-23-2012
jiam912's Avatar
jiam912 jiam912 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 3 September 2014, 4:43 PM EDT
Location: Ecuador
Posts: 140
Thanks: 99
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 03:42 PM.. Reason: Code tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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-09-2012 11:34 PM
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 12:01 PM
Find duplicate value comparing 2 files and create an output ricky007 Shell Programming and Scripting 2 02-26-2008 03:57 PM
Dynamically redirect output to duplicate files ??? nsinha Shell Programming and Scripting 3 10-09-2007 07:04 AM
Removing duplicate files from list with different path vino Shell Programming and Scripting 10 05-12-2005 08:44 AM



All times are GMT -4. The time now is 07:35 PM.