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.
I have a file with 200 000 lines and I want to append the fields of each line based on matching first field. The resulting file should have 70 000 columns but has "only" 18 000. The command I'm using is working perfectly with a smaller file, wich lead to 14 000 columns. Could there be a limit in number of fields that awk can handle ? Here's my awk command :
Code:
awk -F, 'END { for (k in _) print _[k] } { _[$1] = $1 in _ ? _[$1] FS $4 : $1","$4 } ' file > out
Also, this command writes ^M (windows line break) after each columns. Removing them is easy but where do they come from ?
So to confirm, you have a csv file that has at least 70,000 lines where the first field is the same?
The issue is not the number of columns but more likely the number of characters a single string can contain.
Unfortunately I was not able to find a definitive answer to whether a maximum size exists
So my suggestion would be to perhaps use the the length function and once a particular entry reaches a certain size, split it into a new one.
Maybe using dos2unix will help to remove the CR in the file - does it originate form Windows?
Could the problem be rephrased: first sort the CSV file by the first field and then it would be to output each $4 from all lines until $1 changes - then output the final '\n' of the line.
Reuti, the problem with th ^M is not to remove them (with dos2unix, sed ect...) but why are they there. This file as never seen a windows machine...
Ok, then: which application creates the file? Maybe it's defined there that CSV creates a file which is compatible to Windows as outlined in RFC 4180. It's there because it should be there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.