Linux shell script awk command too many open files

I am trying to split a large file based on a template. For this I use the awk command. After creating a certain number of files, it gives an error: too many open files.

Command:

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

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

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

Thanks.

+6
source share
1 answer

Before starting in the following file, close the previous file:

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

All Articles