How to Remove comma as last character in end of last line of file?

how to Remove comma as last charector in end of last line of file:

example:

input file
---------------

aaaaaa,
bbbbbb,
cccc,
12345,

____________

output file :
-----------
aaaaaa,
bbbbbb,
cccc,
12345
-----------

 sed '$s/,$//' filename

tr ,

I have given2 space after comma

thanks Subbeh !!! it worked for me :slight_smile:
Could you please explain how it works ?

It's pretty simple, the first '$' specifies the last line, then you tell sed to remove ',$' ($ is end of line) from the string.

thanks for advise ....actually was not in touch with unix script from 1 year :slight_smile:
anyway thanks for prompt checking and replying on site

Using awk

awk 'FNR==NR{tot=NR; next} FNR==tot{sub(/,/,"")}1' file file
aaaaaa,
bbbbbb,
cccc,
12345

another variation

awk 'NR==tot{sub(/,/,"")}1' tot=$(wc -l < file) file