使用bash脚本在两个分裂的文本文件 [英] split text file in two using bash script

查看:128
本文介绍了使用bash脚本在两个分裂的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标志中间的某个文本文件:

I have a text file with a marker somewhere in the middle:

one
two
three
blah-blah *MARKER* blah-blah
four
five
six
...

我只需要这个文件在两个文件中裂开,首先包含一切之前的标记的,之后的标记的第二个包含一个一切。似乎它可以使用awk一行来完成或sed的,我只是不知道如何。

I just need to split this file in two files, first containing everything before MARKER, and second one containing everything after MARKER. It seems it can be done in one line with awk or sed, I just can't figure out how.

我试过最简单的方式 - 使用csplit可,但则csplit不统一code文本发挥好

I tried the easy way — using csplit, but csplit doesn't play well with Unicode text.

推荐答案

您可以使用awk很容易做到这一点。

you can do it easily with awk

awk -vRS="MARKER" '{print $0>NR".txt"}' file

这篇关于使用bash脚本在两个分裂的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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