使用 awk 将文件中的每 5 行读取到名称为 file_# 的新文件中,其中 # 根据当前迭代递增

Using awk to read every 5 lines from a file to a new file with name file_# where # is incremented based on the current iteration

我有一个包含 200 行的文件。我希望 awk 每 5 行读取一次并为其创建一个文件(其文件名为 file_#)。

当程序读取前 5 行时,它将为这 5 行创建 file_1。当程序读取 6-10 行时,它将为这 5 行创建 file_2。这必须完成直到到达文件末尾。

不需要 awk 或任何花哨的东西。使用 GNU split:

split --numeric-suffixes=1 -l5 file file_