ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
but i'm hung up with the last field .
As you can see above, I'm using the default Field Separator, which works up until the last field. Any help is appreciated
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
Here's a sed solution that appears to work, at least on the above example.
Code:
sed -r -e 's/,?[ ]/,/g' -e 's/[][]//g' -e 's/[,]/ /8g'
Note how you can add a number at the end of the s option to specify which specific instance of the pattern in the line to operate on. Adding a g then makes it mean from that position onwards. (There is no a simple way to go from the start of the line to a specific position, however.)
Here's the output I get:
Code:
2010-10-10,14:39:11,634,0000,1AB,:123ABC42-E4CF-1A99-567F-1234567890AB,SOMEINFORMATIONHERE,Some Information here
No code supplied has allowed for this, not even the OP's original example.
Yes I noticed that. I assumed the the two lines are only presented as an example of input and output format, the second line being a result of processing a different input than the first line, since that was the only possibility to allow a sensible solution based on the information provided. Also, the attempted original poster's solution seems to suggest that the desired result is to only change the format. But I may of course be wrong...
I assumed the same as millgates. Although it would've been clearer if the OP had used the same data for both input and output, the desire was clear.
@tekvaio: I'm glad we could help you out, but what we'd really like to hear is what exactly in our posts helped you. It would be polite to give us a bit of detail on what you ended up using and why, and it may also help others who come across the thread later.
Originally Posted by grail View Post
Is it just me or did no one notice that the lines of data are not the same and I don't mean replacing spaces with commas.
Specifically:
Code:
:123ABC42-E4CF-1A99-567F-1234567890AB
:760ED8C2-E4CF-1A99-567F-FBC8606973DA
No code supplied has allowed for this, not even the OP's original example.
Yes I noticed that. I assumed the the two lines are only presented as an example of input and output format, the second line being a result of processing a different input than the first line, since that was the only possibility to allow a sensible solution based on the information provided. Also, the attempted original poster's solution seems to suggest that the desired result is to only change the format. But I may of course be wrong...
yes.. thats correct.. sorry about that, i wrote this post in hurry and wasn't completely accurate at the time.
Quote:
sed -r -e 's/,?[ ]/,/g' -e 's/[][]//g' -e 's/[,]/ /8g'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.