LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Limit in number of fields that awk can handle ? (http://www.linuxquestions.org/questions/programming-9/limit-in-number-of-fields-that-awk-can-handle-866109/)

chargaff 03-02-2011 08:47 PM

Limit in number of fields that awk can handle ?
 
Hi,

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 ?

Working on Ubuntu 10.10

Any help would be greatly appreciated

grail 03-03-2011 02:06 AM

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.

Reuti 03-03-2011 06:19 AM

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.

chargaff 03-03-2011 08:29 AM

Thanks grail an Reuti for your replies

Yes, exactly grail, the file as at least 70,000 lines where the first field is the same.

I will test a solution to split the strings soon, it's a good idea.

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...

Reuti 03-03-2011 08:36 AM

Quote:

Originally Posted by chargaff (Post 4277679)
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.


All times are GMT -5. The time now is 06:37 PM.