繁体   English   中英

我需要使用shell脚本在shell脚本中第一次出现指定单词之前复制文本文件的内容。

[英]I need to copy the contents of a text file just before the first occurance of a specified word in shell script using shell script.

我有一个很大的文本文件,其中一个特定的单词会重复很多次。 我需要在特定单词上方的内容,该单词首先是在Shell脚本的底部找到的,例如:我的文件包含:Tiger,Lion,Cat,Tiger,Man。

如果指定的单词是Tiger,则需要包含Tiger,Lion,Cat,Tiger的新文件

冗长,但类似

$ tac input | sed -n  '/Tiger/, $ p' | tac
Tiger
Lion
Cat
Tiger

从手册页

   tac - concatenate and print files in reverse

试试这个。

sed -r 's/(,Tiger),(.*)/\\1./g'

暂无
暂无

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

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