- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个正则表达式,我想与 sed 一起使用。我想使用 sed,因为我想批量处理几千个文件而我的编辑器不喜欢那样
查找:"some_string":"ab[\s\S\n]+"other_string_
替换:"some_string":"removed text"other_string_
Find 基本上匹配 some_string 和 other_string 之间的所有内容,包括特殊字符,如 , ; - 或 _ 并将其替换为文本已删除的警告。
我正在考虑组合字符类 [[:space:]]
和 [[:alnum:]]
,这不起作用。
最佳答案
在 MacOS FreeBSD 中 sed
, 您可以使用
sed -i '' -e '1h;2,$H;$!d;g' -e 's/"some_string":"ab.*"other_string_/"some_string":"removed text"other_string_/g' file
1h;2,$H;$!d;g
part 将整个文件读入内存,以便所有换行符都暴露给正则表达式,然后
"some_string":"ab.*"other_string_
匹配来自
"some_string":"ab
的文本直到最后一次出现
"other_string_
并替换为 RHS 文本。
-i ''
使用 FreeBSD
sed
强制执行内联文件修改。
perl
,你真的可以用
-0777
使用
s
启用文件 slurping 的选项修饰符(使
.
匹配任何字符,包括换行符)并使用类似
perl -i -0777 's/"some_string":"\Kab.*(?="other_string_)/removed text/gs' file
这里,
"some_string":"
- 匹配文字 \K
- 从当前匹配内存缓冲区中省略到目前为止匹配的文本 ab
- 匹配 ab
.*
- 尽可能多的零个或多个字符.*?
- 任何零个或多个字符为 少数 尽可能(?="other_string_)
- 正向前瞻(匹配文本但不附加到匹配值)确保存在 "other_string_
立即在右侧。 关于regex - 我怎样才能用 sed 表达这个正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66258871/
我需要一些有关 Sed 的帮助。我在 Windows 和 Mac OSX 上使用它。我需要 Sed 添加一个 每 4 行,在第一个 之后找到,并在 上停止这样做 我就是找不到办法做到这一点。每
我是一个管理很多网站的轮换团队的一员,我们继承了一个网站的一些特别糟糕的代码,我们正在彻底重新设计该网站。非常可怕的是,开发服务器上有一些链接将您带到实时服务器和旧域以及许多其他可怕的事情。 我一直在
我正在尝试在脚本中运行以下表达式以查找设备并在html文件中更改与该设备关联的字段之一。 sed -e "s/$OLDTEST/$TESTING/" -e "s/$CURRENTVALU/$NEWST
我正在尝试使用 sed 删除所有出现的 #ifdef _WIN32 #endif #ifdef 和 #endif 之间存在的所有内容都是空行。我使用 sed 的经验有限,我已经阅读了一些关于多行功能的
以下命令是什么意思: sed -e '/SUBCKT\ REDBK128S4_LC/,/ENDS/ d' $1 什么,代表? 最佳答案 如果指定两个地址,则指定执行命令的行范围。在您的 sed表达
我需要使用sed注释匹配行和其后的4行的帮助。 在文本文件中。 我的文本文件是这样的: [myprocess-a] property1=1 property2=2 property3=3 proper
我想要一个sed命令来完成以下任务: $ sed s'/:/ /g' sed s'/=/ /g' 也就是说,我想写 sed s'// /g' 并用空格替换=和:。 最佳答案 sed s'/[:=]/
我想在大文件中每隔30行插入一个字符串。我正在使用mini-sed,它不支持〜(波浪号)范围运算符。我正在寻找仅sed的解决方案。 最佳答案 该线程是如何使事情过于复杂的另一个示例。应该这样做: se
有人可以帮我吗? grep " 287 " file.txt | grep "HI" | sed -i 's/HIS/HID/g' sed: no input files 也尝试过 xargs gre
这个问题已经有答案了: How can I replace each newline (\n) with a space using sed? (43 个回答) 已关闭2 年前。 如何使用 sed 命
我们需要屏蔽信用卡号。屏蔽除最后 4 位数字以外的所有数字。我正在尝试使用 SED。由于信用卡号长度从 12 位到 19 位不等,我正在尝试编写正则表达式。以下代码将收到字符串。如果它包含形式为“CA
例如: sed 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' abc.txt 's@' 、 '(' 、 '\?' 、'&' 和 '@' 等含义是什么? 如何找到最合适
我们有一个进程可以使用包含 sed 的文件更改管道输入的命令。 我需要用变量值替换输入中的占位符,例如在一个 -e我可以运行的命令类型; $ echo "Today is XX" | sed -e "
这个问题在这里已经有了答案: Using different delimiters in sed commands and range addresses (3 个答案) 关闭1 年前。 我想问 2
是的,我搜索了该网站,但我认为我没有看到任何东西可以专门解决我无法克服的非常(我想很简单)的问题。 我正在上 Linux 类(class),有人问我这个问题: Use the sed command
我有一个看起来像这样的文件路径列表 abc/def/ghi/jl/r1/r2 abc/def/ghi/jl/r9/r11 abc/nyc/ghi/jl/r3/r4/r5 abc/nyc/ghi/jl/
我在这个文件中有这个文本: test.php $databases = array ( 'default' => array ( 'default' => array (
让我们考虑一个包含以下语句的 SQL 文件作为输入(即 myTable.sql): EXECUTE IMMEDIATE 'CREATE OR REPLACE PUBLIC SYNONYM ' || m
好的,谷歌搜索几分钟后,这似乎是在每行输出前加上 sed 前缀的常规方法 但是我得到一个我不明白的错误。 这是什么意思,我该如何解决? $ sed 's/^/#/' test.txt sed: -e
我有以下文件列表: r1 r2 10 r11 r99 我正在尝试替换 ls 输出中文件名中 r 之后的所有数字 我要找的结果: rA rA rA rA rA 使用下面的 sed 命令我可以匹配
我是一名优秀的程序员,十分优秀!