I want to join two files according to number in the file, two number same file Toyota   model1 BMW      model2Benz     model3BMW      model4 BMW      model5Benz     model6 Benz     model7and second fileclass C    model1class E    model2class A    model3class W    model4class W    model5class C    model6class A    model7I want to join the two file according to the number, like this, joining each model number with each other in one file.  Toyota      class C  model1BMW         class E  model2Benz        class A  model3BMW         class W  model4 BMW         class W  model5  Benz        Class C  model6Benz        Class A  model7after that delete the 'model' string My code, sort -V file1 > new_file1 sort -V file2 > new_file2 join newfile1 new_file2 > result.txtsed 's/model[(1-9)]//g' result.txt > result_1.txtthe problem I'm getting an Error while joining the files  join: file1.txt:10: is not sorted: 03Benz   model   249join: file2.txt:4: is not sorted: BMW   model   2what if I want to count frequency after that    ( this pair happen in the text 2 times) after joined Toyota      class C  1BMW         class E  1Benz        class A  2BMW         class W  2Benz        Class C  1
How to Sort and join according to Number/Counter inside the file?
text processing;sed;sort;join
Use join.It looks like changing the first space character in the file to something other than space will be sufficient to convert the file whitespace-delimited records.Here's an implementation that replaces the first space with % and then joins on the second column of each file.$ cat file2 | sed -e 's/ /%/' | join -1 2 -2 2 - file1or $ <file2 sed -e 's/ /%/' | join -1 2 -2 2 - file1which producesmodel1 class%C Toyotamodel2 class%E BMWmodel3 class%A Benzmodel4 class%W BMWmodel5 class%W BMWmodel6 class%C Benzmodel7 class%A BenzIf you need to convert it to a tab-delimited format, you can use tr.tr ' %' '\t ' 