sort file adding extra character

HI all
i have this script :

#!/bin/bash
sort /usr/tmp/"REPORT"$1 -o \
 /usr/tmp/"SREPORT"$1 -k 1,7 -S 150

end of script
now i'm doing this command :

ls -lsgt *REPORT*
4 -rw-r--r--       300 Sep 16 REPORT54784
4 -rw-r--r--       301 Sep 16 SREPORT54784

as you can see the sorted file as an extra character , which i cannot understand why

i'm using this command's syntax on other files , and the sorted and unsorted file , are in the same size ,
can someone help ?
thanks in advnaced
Naama

Can not understand your problem. Where is the extra character. Do you mean SREPORT ?

Your command will sort the file /usr/tmp/"REPORT"$ and write the output on /usr/tmp/"SREPORT"$1

Can you please post the input and the expected output.

Hi
what i meant is that the number of the characters in the file REPORT54784
are 300 , while in the SREPORT54784 the number of the characters are 301
i didn't mean to the name of the file .i can't display the input and output it's write that it's binary files.
please help
Thanks

sort probably added a missing newline at the end.

$ printf 'z\na' > unsorted
$ sort unsorted > sorted
$ ls -l unsorted sorted | awk '{print $5, $9}'
4 sorted
3 unsorted
$ od -c unsorted 
0000000    z  \n   a                                                    
0000003
$ od -c sorted   
0000000    a  \n   z  \n                                                
0000004

Also, sort is a text utility. Don't be surprised if you observe odd behavior with arbitrary binary data.

Regards,
Alister

1 Like

Hi
i did your last commands which show exactly what you've posted.
$ od -c REPORT54784
0000000 z \n a
0000003
$ od -c SREPORT54784
0000000 a \n z \n
0000004
my problem is that i have a program which accept this file in constant size of the record.
can i always be sure that the addition will be newline ? and not some other character ?
and if so how can i overcome this problem since i want to keep the file in the same size , due to what i've wrote above.
thanks in advanced
Naama