在某些模式之前添加文本时使用忽略大小写的 sed [英] Use sed with ignore case while adding text before some pattern
本文介绍了在某些模式之前添加文本时使用忽略大小写的 sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
sed -i '/first/i 这行要加'
在这种情况下,如何在搜索模式=first时忽略大小写
解决方案
您可以使用以下内容:
sed 's/[Ff][Ii][Rr][Ss][Tt]/last/g' 文件
否则,您有 /I
和 n/i
标志:
sed 's/first/last/Ig' 文件
来自 man sed:><块引用>
我
我
正则表达式匹配的 I 修饰符是一个 GNU 扩展,它使 sed 以不区分大小写的方式匹配正则表达式.
测试
$ cat 文件第一的第一的第一的一等奖$ sed 's/[Ff][Ii][Rr][Ss][Tt]/last/g'文件最后的最后的最后的一等奖$ sed 's/first/last/Ig' 文件最后的最后的最后的一等奖
sed -i '/first/i This line to be added'
In this case,how to ignore case while searching for pattern =first
解决方案
You can use the following:
sed 's/[Ff][Ii][Rr][Ss][Tt]/last/g' file
Otherwise, you have the /I
and n/i
flags:
sed 's/first/last/Ig' file
From man sed:
I
i
The I modifier to regular-expression matching is a GNU extension which makes sed match regexp in a case-insensitive manner.
Test
$ cat file
first
FiRst
FIRST
fir3st
$ sed 's/[Ff][Ii][Rr][Ss][Tt]/last/g' file
last
last
last
fir3st
$ sed 's/first/last/Ig' file
last
last
last
fir3st
这篇关于在某些模式之前添加文本时使用忽略大小写的 sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文