Duplicate files and output list

Gents,

I have a file like this.

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

1 1 2
2 3 4 5
3 6 7

Thanks in advance for your support :b:

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

also try:

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

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

1 1 2
2 3 4 5
3 6 7

What do you mean by this...

If you mean duplicate lines then use:

uniq -d

[i]I found the solution like this

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

Thanks

small addition to previous code.. This should work for your input file:)

awk '{a[$1]=a[$1]?a[$1]" "$2:$0}END{for(i in a){n=split(a,P);if(n > 2){print a}}}' file
1 Like

Many thanks for you help