Sorting the records for a file

hi,
Please suggest me how to do this logic
say i am dynamically taking a file name into the script.
when ever a file name it should sort the all the records based on the first character in every line except the heading line and ending line.
for example
file1
heading
bshdshdskjadkljaslkdj
adjnsjkdnsjdnjkdksljd
ckjdkljdkljlkdjkl;skjd;l
ending notes

o/p

file1
heading
adjnsjkdnsjdnjkdksljd
bshdshdskjadkljaslkdj
ckjdkljdkljlkdjkl;skjd;l
ending notes
regards
Angel

To really sort only on the first character an leave the order in tact for all the characters that follow you would need to use stable sort. In GNU sort this is the -s option. You would have to look up the equivalent option in your sort with man sort .

head -1 file > file.out
sed '1d;$d' file | sort -s -k1.1,1.1 >> file.out
tail -1 file >> file.out

If you need a regular sort you can replace the middle line with:

sed '1d;$d' file | sort  >> file.out

If you need a regular sort and the ; is a field separator you can replace the middle line with:

sed '1d;$d' file | sort -t';' >> file.out