for example, i have two file:
file A: 1,2,3,4,5,6
file B: 5,6,7,8,9,10
if i want to join the together and become file C, without any duplication, like:
file C: 1,2,3,4,5,6,7,8,9,10
what UNIX command should I use to combin two files together without any data duplication.
Thank you very much, everybody.
In UNIX, what command could join two content from different file together, without any duplication?
If the values are each on their own line, then:
cat A B | sort -n | uniq %26gt; C
If the text you have is not numbers, don't specify "-n" on sort.
If you want to know how many instances of each number was in the file, then
cat A B | sort -n | uniq -c %26gt; C
(uniq -c does a "count" of values but only prints each unique value once).
If the files contain lists of numbers separated by commas (as your example shows) then you could try:
cat A B | sed -e 's/,/\n/g' | sort -n | uniq %26gt; C
But if you want all of the results to end up back into a single line, again like your example shows, then:
cat A B | sed -e 's/,/\n/g' | sort -n | uniq | sed -e 'N s/\n/,/g' %26gt; C
Alternatively you could do all of this with a single Perl script...
Reply:I believe it is "cat"
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment