Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
Registered User
 
Join Date: Aug 2010
Location: Ecuador
Posts: 68
Thanks: 44
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
Registered User
 
Join Date: Mar 2012
Location: Pune, India
Posts: 1,485
Thanks: 56
Thanked 425 Times in 421 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
Registered User
 
Join Date: Sep 2012
Location: Houston, Texas, USA
Posts: 571
Thanks: 0
Thanked 173 Times in 167 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
Registered User
 
Join Date: Aug 2010
Location: Ecuador
Posts: 68
Thanks: 44
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
Registered User
 
Join Date: Oct 2007
Location: USA
Posts: 1,301
Thanks: 11
Thanked 99 Times in 95 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
Registered User
 
Join Date: Sep 2012
Location: Houston, Texas, USA
Posts: 571
Thanks: 0
Thanked 173 Times in 167 Posts
If you mean duplicate lines then use:

Code:
uniq -d

Sponsored Links
    #7  
Old 10-23-2012
Registered User
 
Join Date: Aug 2010
Location: Ecuador
Posts: 68
Thanks: 44
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 03:55 PM.