不区分大小写的搜索与sed匹配? [英] Case insensitive search matching with sed?
本文介绍了不区分大小写的搜索与sed匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用SED从两个单词(例如帐户和已识别)中提取文本,我希望搜索不区分大小写。因此,我尝试使用I参数,但是收到以下错误消息:
I'm trying to use SED to extract text from two words, such as "Account" and "Recognized", and I'd like that the searching be case insensitive. So I tried to use the I parameter, but receive this error message:
cat Security.txt | sed -n /帐户/,/已识别/ pI | sed -e'1d'-e'$ d'
sed:-e表达式#1,字符24:命令后的多余字符
推荐答案
避免对猫的无用使用
/ pattern / I
是如何在 sed中指定不区分大小写的匹配
sed -n "/Account/I,/Recognized/Ip" Security.txt | sed -e '1d' -e '$d'
您可以使用单个 sed
命令来实现相同的目的:
You can use single sed
command to achieve the same:
sed -n '/account/I,/recognized/I{/account/I!{/recognized/I!p}}' Security.txt
或 awk
awk 'BEGIN{IGNORECASE=1} /account/{f=1; next} /recognized/{f=0} f' Security.txt
参考文献:
- How to select lines between two patterns?
这篇关于不区分大小写的搜索与sed匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文