I need to remove the last comma of each line.I have only one csv file, which looks like this:98,N,N,N,N,S,99,N,N,N,N,S,101,Y,Y,Y,Y,S,I have the following script, but it is not working:for fname in conv2015_10_LogicalComponent_CosProfile.csvdo   sed 's/.$//' $fname > tmp.tmp   mv tmp.tmp $fnamedone
How to Remove last comma of each line on csv using linux
shell script;text processing
this should work.    for fname in conv2015_10_LogicalComponent_CosProfile.csv       do       cat $fname | sed 's/.$//' > tmp.tmp       mv tmp.tmp $fname    doneAnother option is if you use GNU Sed -i option:then you only need to do this:sed -i 's/.$//' filenameAdditionaly to clarify why . is used there instead of ,. This is regular expression which matches almost any character, so if there is ; it would replace that as well. You be more precise you can change .$ to ,$.EDIT:I noticed that you mentioned that you actually have whitespaces at the end. So this code works, even with whitespaces. Proven on Solaris.cat filename | sed 's/,[[:blank:]]*$//g > tmp.tmpmv tmp.tmp desired_filename