Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 分隔符编号出现后拆分文件_Shell_Awk - Fatal编程技术网

Shell 分隔符编号出现后拆分文件

Shell 分隔符编号出现后拆分文件,shell,awk,Shell,Awk,我的问题与中的回答基本相同,只是解决方案将在拆分之前删除分隔符。在保留初始文件的所有字符的同时,如何在第n次出现分隔符后分割失败?示例文件: aaa bbb $$$$ ccc ddd eee $$$$ fff ggg hhhhh $$$$ 每发生第二次后分割$$$$ awk '/^\$\$\$\$$/ { if(++delim % 2 == 0) { next } } { file = sprintf("chunk%s.txt", int(delim / 2)); print; END { p

我的问题与中的回答基本相同,只是解决方案将在拆分之前删除分隔符。在保留初始文件的所有字符的同时,如何在第n次出现分隔符后分割失败?示例文件:

aaa
bbb
$$$$
ccc
ddd
eee
$$$$
fff
ggg
hhhhh
$$$$
每发生第二次后分割$$$$

awk '/^\$\$\$\$$/ { if(++delim % 2 == 0) { next } } { file = sprintf("chunk%s.txt", int(delim / 2)); print; END { print "ds" } }' < file
awk'/^\$\$\$\$$$/{if(++delim%2==0){next}}{file=sprintf(“chunk%s.txt”,int(delim/2));打印;结束{print“ds”}}}

将删除块文件末尾的分隔符,如果我正确获得它,并且您希望在每出现第二次
$$$
时分割文件,请尝试以下操作

awk -v file="1" -v occur="2" '
{
  print > (file".txt")
}
/^\$\$\$\$$/{
  count++
  if(count%occur==0){
    if(file){
      close(file".txt")
      ++file
    }
  }
}
'  Input_file

预期的产量是多少?这对我很有效。谢谢快速跟进:让输出名称增加一组字母有什么好主意吗?aaaa,aaab,aaac像分裂一样?@doom4,不清楚,直到它什么时候应该消失?请您在同一页上添加更多细节;总是建议在帖子中添加预期的输出。