0

I have two very long comma delimited files. Each line has around 101 columns on both the files and each file has 41705 records.

Before Sorting File A & File B both:-


01B60D9F4DEB83,FY 
01B60D9F4DEB83,AU
01B60D9F4DEB83,BB
01B60D9F4DEB83,BB
01B60D9F4DEB83,JA

After Sorting File A:-


01B60D9F4DEB83,BB
01B60D9F4DEB83,FY
01B60D9F4DEB83,BB
01B60D9F4DEB83,AU
01B60D9F4DEB83,JA

After Sorting File B:-


01B60D9F4DEB83,FY 
01B60D9F4DEB83,BB
01B60D9F4DEB83,BB
01B60D9F4DEB83,AU
01B60D9F4DEB83,JA

Command used on bolth Solaris & Linux :-

sort -t"," -k1,1 fileA.csv > FileA_Sort.csv
sort -t"," -k1,1 fileB.csv > FileB_Sort.csv

Can anybody point me why we are getting differences on the same values for the same starting sequence? What am I missing?

5
  • Could they have different whitespace at the ends of the lines?
    – Barmar
    Mar 29, 2017 at 16:51
  • @toolic He said that's the contents of both files.
    – Barmar
    Mar 29, 2017 at 16:51
  • SO is for programming questions, not questions about using or configuring Linux. Try SuperUser.com or unix.stackexchange.com.
    – Barmar
    Mar 29, 2017 at 16:51
  • Where did you get anything related to using or configuring linux? Don't comment just for the heck of it.. This sorting is a small part of a big program where I was stuck. How is this not a forum to ask programming/sorting related questions? Don't teach me what SO is.
    – KChow
    Mar 30, 2017 at 7:48
  • It looks like you're just asking how to use the sort command. There's no script shown in the question.
    – Barmar
    Mar 30, 2017 at 15:42

1 Answer 1

1

you are sorting on first column. When many records have the same value in the first column, they can be in any random order. For big files, the algorithm depends of the available memory (http://vkundeti.blogspot.fr/2008/03/tech-algorithmic-details-of-unix-sort.html).

If you want to preserve the order, you should add the option '-s'.

1
  • It worked. Just what I needed. Thanks man !!!
    – KChow
    Mar 29, 2017 at 18:42

You must log in to answer this question.