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
-----------
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
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
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