linux - Bash awk 脚本 : document splitter issue

标签 linux bash shell awk

我编写此脚本是为了将一个大型文档拆分为多个 500 行的文档。它适用于第一个渲染文件的异常(exception)情况,该文件短一行(499 行)。 主文档的第一行正确传输到“file01”,“file02”的第 1 行是“file01”第 499 行的下一个连续行。 下面是我的脚本。谢谢你们。 在终端中使用:Splitter.sh "filetosplit.txt"

#!/bin/bash

find $1 -type f | sort -n > $1_TapeList.txt


mkdir 500FileTL_$1
cd  500FileTL_$1
awk '{outfile=sprintf("file%02d.txt",NR/500);print > outfile}' ../$1_TapeList.txt

最佳答案

NR 从 1 开始,而不是 0。所以你可以像这样修复它

awk '{outfile=sprintf("file%02d.txt",(NR-1)/500) ...

关于linux - Bash awk 脚本 : document splitter issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42103058/

相关文章:

linux - 使用 Linux 匹配两个文件中的数字

android - 如何在没有源码的情况下构建Android?

linux - 在 MATLAB 中执行 .mex 文件时,如何诊断为什么无法加载 .so 文件?

bash - 以编程方式执行到 docker 容器中

linux - 我的 bash 脚本 (linux) 中的错误计数器在 while 语句期间不计数

python - 在 Windows 计算机上从 Python 运行 Linux 命令

bash - 启动 emacs 时的 exec-path-from-shell 消息

linux - "the kernel address space"是什么?

bash - 如果一个目录的其他权限是可写的,即使该文件不可写,其他用户也可以修改该文件

shell - AWK(意外的换行符或字符串结尾)