LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to remove commas at the end of rows (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-commas-at-the-end-of-rows-4175591496/)

freeroute 10-15-2016 06:35 PM

How to remove commas at the end of rows
 
I would like to remove commas , at the end of each line in my file.
sed only remove the last comma character, but I would like to remove all the commas (and maybe all other character, like:::) at the end of a lines.
My command: sed 's/,$//' file

for example my file contains:
Solaris,
Debian,,,,,
Kubuntu,,
Unix,,,,,,,,
Apache:::

Thanks in advance.

rknichols 10-15-2016 07:06 PM

Pretty straightforward.
Code:

sed 's/,*$//' file                # remove all trailing commas
sed 's/[,:]*$//' file              # remove all trailing commas and colons
sed 's/[^[:alnum:]]*$//' file      # remove all trailing non-alphanumeric characters


freeroute 10-15-2016 07:15 PM

Thank you very much.

jpollard 10-15-2016 07:31 PM

sorry. mixed up the patterns.

szboardstretcher 10-17-2016 01:09 PM

Old style sed regex using () instead of [], removing all trailing commas and colons:

Code:

sed 's/\(,\|:\)*$//' input


All times are GMT -5. The time now is 04:54 AM.