English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

2006-11-16 05:57:15 · 3 answers · asked by TT 1 in Computers & Internet Programming & Design

3 answers

If the values are each on their own line, then:

cat A B | sort -n | uniq > 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 > 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 > 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' > C

Alternatively you could do all of this with a single Perl script...

2006-11-16 07:00:45 · answer #1 · answered by RGB_Mars 3 · 0 0

the following is a somewhat diverse answer: cat file_a.textual content file_b.textual content | kind -n | uniq > file_c.textual content the version the following (from Mervin's answer) is that the sorting and the elimination of duplicates are done by separate equipment. The -n option for kind specifies that the sorting must be done numerically, fairly of the default it really is alphabetically. In both circumstances, besides the undeniable fact that, we are assuming that the values in each and each and every document are saved with one decision in step with line, like this: a million 2 3 etc. If the information extremely comprise a itemizing of numbers all on an similar line, it really is one way of examining the format of your question, then the answer might want to be thoroughly diverse. i desire that this allows!

2016-11-29 04:59:28 · answer #2 · answered by ? 4 · 0 0

I believe it is "cat"

2006-11-16 05:58:37 · answer #3 · answered by whome 3 · 0 0

fedest.com, questions and answers