简体   繁体   English

如何根据给定的模式将linux中的文本文件从文件底部拆分到顶部

[英]How to split a text file in linux from the bottom of the file to the top based on a given pattern

How to split (it doesn't matter what command) a text file in Linux from the bottom of the file to the top based on a given pattern. 如何根据给定的模式在Linux中将文本文件从文件底部拆分到顶部(无论使用什么命令都无所谓)。

If I have the file: 如果我有文件:

111
aaa
222
aaa
333
aaa

The output should be 输出应为

1st file
    333
    aaa

2nd file
    222
    aaa

3rd file
    111
    aaa

Thank you. 谢谢。

Reverse the file with tac and then run it through csplit . tac反转文件,然后通过csplit运行它。 The -k option means that you don't need to know the number of splits in advance. -k选项意味着您不需要预先知道分割数。

tac file | tac文件| csplit -s -k - "/aaa/+1" "{99}" csplit -s -k-“ / aaa / + 1”“ {99}”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM