Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一种方法来读取和删除某个文件中找到的两个不同字符串之间的文本,然后删除这两个字符串。就像一个“剪切命令”。我想将文本存储在变量中。
我看到了关于在两个字符串之间读取文本的帖子,但我也不知道如何删除它。
我打算在 bash 中执行存储的文本。效率是可取的。此脚本不会用于大文件,但它可能会按顺序执行多次,因此脚本运行得越快越好。
存储的文本通常会有特殊字符。
谢谢
通过环境指定开始和结束字符串,以及在 perl 命令行上使用的文件:
export START_STRING='abc def' export END_STRING='ghi jkl' perl -0777 -i -wpe's/\Q$ENV{START_STRING}\E(.*)\Q$ENV{END_STRING}\E/s;print STDERR $1' file_to_use 2>savedtext