[英]How do I get sed to read from standard input?
我在嘗試
grep searchterm myfile.csv | sed 's/replaceme/withthis/g'
並得到
unknown option to `s'
我究竟做錯了什么?
編輯:
根據評論,代碼實際上是正確的。 我的完整代碼類似於以下內容
grep searchterm myfile.csv | sed 's/replaceme/withthis/g'
# my comment
似乎由於某種原因,我的評論被作為輸入提供給sed。 很奇怪。
使用--expression選項
grep searchterm myfile.csv | sed --expression='s/replaceme/withthis/g'
使用“-e”指定sed表達式
cat input.txt | sed -e 's/foo/bar/g'
要從stdin而不是文件中生成sed
catch,你應該使用-e
。
像這樣:
curl -k -u admin:admin https://$HOSTNAME:9070/api/tm/3.8/status/$HOSTNAME/statistics/traffic_ips/trafc_ip/ | sed -e 's/["{}]//g' |sed -e 's/[]]//g' |sed -e 's/[\[]//g' |awk 'BEGIN{FS=":"} {print $4}'
如果您嘗試對文件中的文本進行就地更新,那么在我看來這更容易推理。
grep -Rl text_to_find directory_to_search 2>/dev/null | while read line; do sed -i 's/text_to_find/replacement_text/g' $line; done
vi myfile.csv
打開文件 :%s/replaceme/withthis/
:wq
並按Enter鍵 現在,您將在文件中使用新模式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.