How can we remove comma from end of each line ?

Hi,

How can we remove the comma from the end of each line.

I have a csv file in below format.

file.csv

 
Name,age,gender,location,
Joel,18,M,Newyork,
Monoj,21,M,Japan,
Litu,23,M,turki,

Expected o/p
file1.csv

 
Name,age,gender,location
Joel,18,M,Newyork
Monoj,21,M,Japan
Litu,23,M,turki

Using shell script command how can we do this. Kindly suggest.

try

sed '$s/.$//' filename 
1 Like

Hello,

Here is an awk utility for same.

awk 'gsub(/\,$/,X) 1' file_name

Output will be as follows.

Name,age,gender,location
Joel,18,M,Newyork
Monoj,21,M,Japan
Litu,23,M,turki

Thanks,
R. Singh

1 Like

Its not working dear.

 
sed '$s/.$//' filename

Below is the actual data I have in csv file.

 
Template,Target Server,Target Component,Rule Group,Rule,Rule Reference Number,Rule Definition,Mismatched Conditions,Result,Documented Exception,Compliant,Exception Name,Exception Reference,Expiration Date,
 
RHEL_Pwd_Compliance,Server1,RHEL_Pwd_Compliance (Server1),/User Exist,User cpm,,"""Extended Object Entry:RHEL_Pwd_Compliance//rootUser"".""Value1 as String (All OS)"" equals ""Available""",,Pass,,Y,,,,

Expected output

 
Template,Target Server,Target Component,Rule Group,Rule,Rule Reference Number,Rule Definition,Mismatched Conditions,Result,Documented Exception,Compliant,Exception Name,Exception Reference,Expiration Date
 
RHEL_Pwd_Compliance,Server1,RHEL_Pwd_Compliance (Server1),/User Exist,User cpm,,"""Extended Object Entry:RHEL_Pwd_Compliance//rootUser"".""Value1 as String (All OS)"" equals ""Available""",,Pass,,Y,,,

---------- Post updated at 04:41 PM ---------- Previous update was at 04:33 PM ----------

Hi Ravinder,

Thanks for your prompt response. Its working fine.

Regards,
Litu

Change Makarand Dodmis' proposal to

sed 's/,$//' file
1 Like