删除第一个标记之前和第二个标记之后的所有文本
所以,我正在编写一个脚本,并且有一个如下所示的文本文件:
blahblahblahdeleteme
<!-- post -->
This is the text I want to keep! Pick me!!
<!-- post navigation -->
more text please delete me I am not needed....
我想删除第一个和最后一个部分(以及标记,如果容易完成)并将文本保留在中间。
现在,我知道 bash 通常不是解析这样的文本的最佳选择,但由于它很简单,我想我最好还是坚持使用 bash。这像我想象的那么容易吗?
我找到了这篇文章:使用 bash 脚本将文本文件分成两部分
我可以将其分成两个文本文件,然后再分成两个,只保留中间的一个。这是我最好的选择吗?请告诉我!
So, I'm writing a script and I have a text file like this:
blahblahblahdeleteme
<!-- post -->
This is the text I want to keep! Pick me!!
<!-- post navigation -->
more text please delete me I am not needed....
I would like to delete the first and last parts (and the marker, if easily done) and keep the text in the middle.
Now, I know bash isn't usually the best for parsing text like this, but since it's simple I thought I might as well stick with using bash. Is this as easy as I think it should be?
I found this post: split text file in two using bash script
I could split it into two text files then into two more and just keep the middle one. Is that my best bet? Please let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
awk
中这真的很容易:It would be really easy in
awk
: