Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

AWK: cannot open "04477C9A875B80.csv" for output (Too many open files)

I have a large CSV file and need to split it too multiple CSV files, using column 3 as the identifier and the resultant files will be named by the value in column 3

I am using the following:

awk -F ',' '{print > ($3".csv")}' playpass.csv

However I'm getting the error:

awk: cannot open "04477C9A875B80.csv" for output (Too many open files)

I know I need to close the files but after a few attempts, I'm getting nowhere and now back to a blank canvas

I tried the following with no luck as I get the same error

awk -F ',' '{close($1); i++}{print > $1}' query_result_2019-07-20T15_31_42.941Z.csv

Any advice?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're trying to close the output file before you open it to write to it instead of after you've opened it. Change this:

'{close($1); i++}{print > $1}'

to this:

'{print > $1}{close($1); i++}'

There are other issues with your script of course but without sample input/output I don't want to make any suggestions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...