在模式之间的行分别打印单独的文件 [英] print lines between patterns individual separate files

查看:72
本文介绍了在模式之间的行分别打印单独的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个超过5000行的大文件,其重复模式如下所示:

I have a big file of 5000+ lines which has a repeated pattern like shown below:

ABC
111
222
333
XYZ

ABC
444
555
666
777
XYZ

..
..

ABC
777777777
888888888
999999999
222
333
111
XYZ

我想提取"ABC"和"XYZ"之间的内容,并将其写入单独的文件中.

I would like to extract contents between each 'ABC' and 'XYZ' and write it to a separate file.

例如:file1应该具有

Ex: file1 should have

ABC
111
222
333
XYZ

File2应该具有

ABC
444
555
666
777
XYZ

Filen应该有

ABC
777777777
888888888
999999999
222
333
111
XYZ

以此类推.

我们如何实现这一目标?我读了下面这些线程,但它只写一个文件.对我的情况没有帮助.

How could we achieve this ? I read these below threads but it writes only one single file. Didn't help for my case.

将两个模式之间的行打印到新文件中

推荐答案

awk '/^ABC/{file="file"c++}{print >>file}' a

这篇关于在模式之间的行分别打印单独的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆