Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-15-2016, 06:35 PM
|
#1
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Rep: 
|
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.
Last edited by freeroute; 10-15-2016 at 06:46 PM.
|
|
|
10-15-2016, 07:06 PM
|
#2
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,815
|
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
|
|
2 members found this post helpful.
|
10-15-2016, 07:15 PM
|
#3
|
Member
Registered: Jul 2016
Location: Hungary
Distribution: Debian
Posts: 69
Original Poster
Rep: 
|
Thank you very much.
|
|
|
10-15-2016, 07:31 PM
|
#4
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
sorry. mixed up the patterns.
Last edited by jpollard; 10-15-2016 at 07:34 PM.
|
|
|
10-17-2016, 01:09 PM
|
#5
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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 03:30 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|