Save output of updated csv file as csv file itself, part 2

Hi,

I have another problem. I want to sort another csv file by the first field.
result.csv

SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw
/home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 
/home/intannf/foto5/2015_0313_090323_155.JPG,0.,-7.77224,110.37312,30.73,996.46,148.76,181.01,181.92,63.82 
/home/intannf/foto5/2015_0313_090142_124.JPG,0.,-7.77224,110.37312,30.73,996.46,148.75,181.13,182.06,63.87 
/home/intannf/foto5/2015_0313_085929_083.JPG,0.,-7.77224,110.37312,30.72,996.46,148.74,180.93,182.12,63.64 
/home/intannf/foto5/2015_0313_090710_225.JPG,0.,-7.77224,110.37312,30.72,996.46,148.77,181.09,181.86,63.78 
/home/intannf/foto5/2015_0313_090628_212.JPG,0.,-7.77223,110.37310,30.72,996.47,148.67,181.09,181.91,63.87 
/home/intannf/foto5/2015_0313_085942_087.JPG,0.,-7.77219,110.37317,30.76,996.47,148.71,181.12,182.17,63.78 
/home/intannf/foto5/2015_0313_090717_227.JPG,0.,-7.77217,110.37315,30.77,996.48,148.66,181.06,182.21,63.87

Output required:

SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw
/home/intannf/foto5/2015_0313_085929_083.JPG,0.,-7.77224,110.37312,30.72,996.46,148.74,180.93,182.12,63.64 
/home/intannf/foto5/2015_0313_085942_087.JPG,0.,-7.77219,110.37317,30.76,996.47,148.71,181.12,182.17,63.78 
/home/intannf/foto5/2015_0313_090142_124.JPG,0.,-7.77224,110.37312,30.73,996.46,148.75,181.13,182.06,63.87 
/home/intannf/foto5/2015_0313_090323_155.JPG,0.,-7.77224,110.37312,30.73,996.46,148.76,181.01,181.92,63.82 
/home/intannf/foto5/2015_0313_090628_212.JPG,0.,-7.77223,110.37310,30.72,996.47,148.67,181.09,181.91,63.87 
/home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 
/home/intannf/foto5/2015_0313_090710_225.JPG,0.,-7.77224,110.37312,30.72,996.46,148.77,181.09,181.86,63.78 
/home/intannf/foto5/2015_0313_090717_227.JPG,0.,-7.77217,110.37315,30.77,996.48,148.66,181.06,182.21,63.87 

I have tried to sort them by sort -n -k2.1,1 -o result.csv -t, result.csv and sort -k2.1,1 -o result.csv -t, result.csv. But what i got that the heading line is always writen below the data. Please help me to figure it out. Thanks in advance.

Regards,
Intan

In your previous thread (Save output of updated cvs file as csv file itself), you were given two methods to perform a numeric sort on a field and keep the file's header in the correct spot. And, you were given lengthy descriptions explaining why both of those methods worked for the input you provided. It looks like you completely ignored those descriptions and tried to apply the tricks provided there (that work when sorting numeric fields with positive values and a single heading line containing alphabetic titles) to sorting completely alphanumeric fields (starting with non-numeric characters).

You say you want to sort your file using the 1st field as your sort key. Your 1st field appears to be absolute pathnames, but you are sorting them as numeric fields when none of the data in that field stats with a number. And, the sort key -k2.1,1 specifies a sort key starting with the 1st character in the second field and ending in the 1st field. The standards do not specify what happens if the end of the sort key comes before the start of the sort key. And, with an alphanumeric sort based on an ASCII codes, / will sort before any alphabetic characters in the heading that you want to remain as the 1st line in your output.

So, to get the output you say you want, you'll have to use the method RudiC suggested in your previous thread to extract the heading from your data and print it, and then sort the rest of your file after throwing away the heading:

(head -1 result.csv && tail -n+2 result.csv | sort) > $$.csv && cp $$.csv result.csv; rm -f $$.csv

Hi, Don Cragun

Sorry for posting my new problem in my previous thread. I have tried your coding. But, it doesn't work with my whole program/script. The program doesn't want to execute those sorting part, but i don't get any errors. When i tried to run those script in a new program, it works well. I just don't know why. Is there other way to sort them?
and my problem is getting more complicated now. I need your help. Please take a look at my problem in my new thread here. Thanks in advance.

Regards,
Intan