Link to home
Start Free TrialLog in
Avatar of sunshine737
sunshine737

asked on

remove last comma in the file

i have a file with the following

file.txt
a,b,c,d,e

I need to remove last comma in the file

can someone tell the command,which i can use?

Thanks
Avatar of ozo
ozo
Flag of United States of America image

If there's only one line in the file
sed -i .bak 's/\(.*\),/\1/' file.txt
if there are more lines in the file, do all the lines contain a comma?
does the last line in the file contain a comma?
Avatar of sunshine737
sunshine737

ASKER

file has only one line.
i just need to delete last comma.
then the above should work
if there are more lines, it will delete the last comma on every line,
(among them the last comma in the file, but may also include other commas)
when i try the sed command, its says

sed: Not a recognized flag: i
Usage:  sed [-n] Script [File ...]
        sed [-n] [-e Script] ... [-f Script_file] ... [File ...]
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Command works perfectly.
if possible could you please explain the command  sed  's/\(.*\),/\1/'

Thanks

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial