我試圖使用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
我試圖使用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
用途:
sed -n "/Account/,/Recognized/Ip"
即更改爲:Ip
代替pI
Security.txt文件有時包含英語句子(例如「Attività賬號」),英語句子(例如「Account Activity」)和您建議的命令,如果它在語法上得到糾正,則不會獲得單詞「帳戶」和「帳戶」。 – user2965031
它應該是'/ Account/I' – Sundeep
@ user2965031我只關注錯誤,但是,如果兩個單詞都必須不區分大小寫,那麼應該使用'/ Account/I'。 –
/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
參考:
這很奇怪,命令sed -n「/ account/I,/ recognized/Ip」適用於「EN-Security.txt」,不適用於「IT-Security.txt」,儘管它們都包含序列「被認可的機器」。 – user2965031
@ user2965031,無論如何你的問題可能並沒有幫助......查看http://stackoverflow.com/help/mcve並相應地編輯你的問題 – Sundeep
你有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
選項允許使用擴展正則表達式。
發佈'security.txt'的內容。 –
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% 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