Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
You could do that several ways, simple shell script or simple sed expression or awk for something you could more easily extend such as for multiple columns or more selective handling.
Do you have exposure to any of those? If so just think about the problem in the context of your skill set and see where that leads.
For examaple, if shell scripting think about a read loop. Or for sed think multi-line replacement. Or for awk think in terms of records and input/output record separators. Also consider whether you might want them reordered (sorted), allow duplicates, etc.
And to get you started, here is a working sed expression:
Code:
':start; $!{N;b start;};s/\n/,/g'
...and a hint for awk, with a suitable ORS it reduces to a single print $0 operation.
For each of the above cases, a simple file redirect will put it into the output file of your choice.
You could do that several ways, simple shell script or simple sed expression or awk for something you could more easily extend such as for multiple columns or more selective handling.
Do you have exposure to any of those? If so just think about the problem in the context of your skill set and see where that leads.
For examaple, if shell scripting think about a read loop. Or for sed think multi-line replacement. Or for awk think in terms of records and input/output record separators. Also consider whether you might want them reordered (sorted), allow duplicates, etc.
And to get you started, here is a working sed expression:
Code:
':start; $!{N;b start;};s/\n/,/g'
...and a hint for awk, with a suitable ORS it reduces to a single print $0 operation.
For each of the above cases, a simple file redirect will put it into the output file of your choice.
I am just learning text manipulation, so no I don't have any exposure to awk or sed yet. I'll do a little research on them tonight and see if I can use that to make this work, thanks for your assistance!
I am just learning text manipulation, so no I don't have any exposure to awk or sed yet. I'll do a little research on them tonight and see if I can use that to make this work, thanks for your assistance!
You are welcome!
Good luck in your learning experience!
Sed and awk are the go-to tools for text manipulation on a Unix/Linux system and are well worth learning! Neither is difficult, but can sometimes appear a little obscure on first contact by new users. Just take a deep breath and work a few examples and you'll be using them for literally everything before you know it!
There are many tutorials for both online, a quick DuckDuckGo turned up these which look useful:
You'll see that both sed and awk rely on regular expressions, so it is worth learning a little about those as a separate topic (although most sed and awk tutorials will necessarily include the basics).
Sed and awk are the go-to tools for text manipulation on a Unix/Linux system and are well worth learning! Neither is difficult, but can sometimes appear a little obscure on first contact by new users. Just take a deep breath and work a few examples and you'll be using them for literally everything before you know it!
There are many tutorials for both online, a quick DuckDuckGo turned up these which look useful:
You'll see that both sed and awk rely on regular expressions, so it is worth learning a little about those as a separate topic (although most sed and awk tutorials will necessarily include the basics).
Those should provide enough examples to get you started, and enough detail if you really want to learn it from the ground up!
So, get yourself oriented and work a few examples, and let us know if you need help past the bumps!
So I was able to accomplish what I needed for my assignment using the following commands:
cat file | xargs | sed -e 's/ /,/g'
I used that based on stuff I found last night with the wonderful google machine. I also read up on the sed command and understand that portion of it. I am struggling with xargs though. I would not have even used it if I didn't find a similar situation and solution on stack overflow. So I understand cat, but why I am I piping to xargs and what exactly is it? Thanks again for answering some questions!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.