2016-08-27 46 views
-1

我试图使用SED从两个单词中提取文本,例如“Account”和“Recognized”,并且我希望搜索不区分大小写。于是,我就用我的参数,但收到此错误信息:sed不区分大小写的搜索匹配

cat Security.txt | sed -n "/Account/,/Recognized/pI" | sed -e '1d' -e '$d' sed: -e expression #1, char 24: extra characters after command

+1

发布'security.txt'的内容。 –

+0

Security.txt可以写在英语和意大利语中,这样的例子: cat EN_Security.txt | sed -n "/Account/,/Recognized/p" | head Account Activity * Checkpoint Flow Started Saturday, April 16, 2016 at 11:26am UTC+02 ::: % cat EN_Security.txt | sed -n "/Account/,/Recognized/p" | tail * Session updated Wednesday, June 17, 2015 at 2:04pm UTC+02 ::: Recognized Machines user2965031

+0

% cat IT-Sicurezza.txt | sed -n "/account/,/Recognized/p" | head Attività account * Login Venerdì 25 settembre 2015 alle ore 17:55 UTC+02 ::: % cat IT-Sicurezza.txt | sed -n "/account/,/Recognized/p" | tail * Login Martedì 4 febbraio 2014 alle ore 20:28 UTC+01 ::: Recognized Machines user2965031

回答

0

用途:

sed -n "/Account/,/Recognized/Ip" 

即更改为:Ip代替pI

+0

Security.txt文件有时包含英语句子(例如“Attività账号”),英语句子(例如“Account Activity”)和您建议的命令,如果它在语法上得到纠正,则不会获得单词“帐户”和“帐户”。 – user2965031

+0

它应该是'/ Account/I' – Sundeep

+0

@ user2965031我只关注错误,但是,如果两个单词都必须不区分大小写,那么应该使用'/ Account/I'。 –

0

避免useless use of cat

/pattern/I是如何指定病例 - 中医在sed

sed -n "/Account/I,/Recognized/Ip" Security.txt | sed -e '1d' -e '$d' 

sitive匹配您可以使用单sed命令来实现相同的:

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 

参考:

+0

这很奇怪,命令sed -n“/ account/I,/ recognized/Ip”适用于“EN-Security.txt”,不适用于“IT-Security.txt”,尽管它们都包含序列“被认可的机器”。 – user2965031

+1

@ user2965031,无论如何你的问题可能并没有帮助......查看http://stackoverflow.com/help/mcve并相应地编辑你的问题 – Sundeep

0

你有useless use of cat,你应该已经直接送入该文件sed。下面可能是一种做法。

$ cat file.txt 
Some stuff Account sllslsljjs Security. 
Another stuff account name and ffss security. 
$ sed -nE 's/^.*account[[:blank:]]*(.*)[[:blank:]]*security.*$/\1/pI' file.txt 
sllslsljjs 
name and ffss 

[[:blank:]]*是贪婪的,会在所需文本前后去掉空格。 -E选项允许使用扩展正则表达式。