sort & match multiple files

Hi,

I have some question and need some guidance how to sort and match multiple files.

  1. all the data in the files are numbers
    e.g. 1234567
    1584752
    2563156

  2. each sorted file have their own ouput. e.g. test.csv -> test_sorted.csv

  3. Then, I need to match all sorted files with source file (sorted) and each matched file have their own ouput. e.g. test_sorted.csv -> test_sorted_matched. csv

Hope you there can give the ideaa how to do a script.

Hi Friend,
I think your problem is not clear enough to attempt, plz give some example and write in details.
Thanks ...

Sort file test.csv in numerical order and get lines common to the result test_sorted.csv and to the source file source_sorted.csv :

sort -n test.csv > test_sorted.csv
com -1 -3 test_sorted.csv source_sorted.csv > test_sorted_matched.csv

Jean-Pierre.

thank you aigle.

But that is for 2 files only. If let say I have more than 2 files e.g. 5 files, then I want to sort all the files in one script. After all sorted, i want to compare all the 5 files with the source file in one script too.

Any ideas?

you can do something like this (not tested) :

source_file=source_sorted.csv
data_files='*.csv'

for file in $data_files
do
   file_dir=$(dirname $file)
   file_name=$(basename $file)
   file_noext=${file_name%.*}
   file_ext=${file_name##*.}

   sorted_file=$file_dir/${file_noext}_sorted.$file_ext
   matched_file=$file_dir/${file_noext}_sorted_matched.$file_ext

   sort -n $file > $sorted_file
   com -1 -3 $sorted_file  $source_file > $matched_file
done

Jean-Pierre.