Too many open files error while running awk comman

2020-03-12 02:55发布

问题:

I am trying to split a big file based on a pattern. I am using awk command for this. After creating certain number of files it gives error: Too many open files.

Command is:

awk '/pattern here/{i++}{print > "file"i}' /input file

Can someone tell me how to close these files? I tried following but it gives error.

    awk '/pattern here/{i++}{print > "file"i}' /input file | close("file"i)

回答1:

Before starting on the next file, close the previous one:

awk '/pattern here/{close("file"i); i++}{print > "file"i}' InputFile


标签: linux shell awk