Linux - NewbieThis 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.
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.
Hi guys. I've been trying to figure out sed for some time with no success. The man pages are confusing at best and I've scoured the internet for help. I've read a few tutorials and getting started guides and things like that but I'm unable to get the right command to do what I want. All I want to do is take a list of IP addresses that are on consecutive lines and print them on the same line separated by commas to a new file. eg:
file "IP1.txt" looks like
1.2.3.4
5.6.7.8
4.3.2.1
8.7.6.5
and I want them to output to "IP2.txt" and look like this:
1.2.3.4, 5.6.7.8, 4.3.2.1, 8.7.6.5
If anyone can help me out with a sed one liner I would really appreciate it and you'd be saving me some more frustration trying to figure it out.
this isn't really something sed is good at without some meddling around. Sed works on data on a line by line basis, so you can't remove the carriage returns as sed never sees them. It's possible to mess with bash environmental variables to change what defines a new record, but this just isn't a good way to learn sed.
I'd use tr instead, which isn't line based... "cat file | tr '\n' ','"
I don't really know why sed!! hence the linux newbie forum! : )
Thanks everyone for the responses... the 'cat file | tr "\n" ","' command worked perfectly! I used to work with someone who accomplished this with 'sed', but lost the command he used. He was considerably smarter than me on computers. This command is so simple! I really appreciate the help! Thanks again!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.