簡體   English   中英

如何在搜索中轉義字符 `<` 和 `>` 並替換傳遞給 sed 的字符串?

[英]How do I escape the characters `<` and `>` in search and replace strings passed to sed?

我想用<title>FRED替換<title> ,使用sed 我已經嘗試了以下無濟於事。

19:46: scratch $ sed -i '/<title>/<title>FRED/' index.html
sed: -e expression #1, char 10: unknown command: `<'
======================================================================================================================
19:47: scratch $ sed -i '/\<title>/<title>FRED/' index.html
sed: -e expression #1, char 11: unknown command: `<'
======================================================================================================================
19:48: scratch $ sed -i "/\<title>/<title>FRED/" index.html
sed: -e expression #1, char 11: unknown command: `<'

那么,如何正確轉義字符<>

或者是我沒有得到的其他東西?

您尚未指定命令。 你大概想要替換命令

sed -i 's/<title>/<title>FRED/' index.html

如果沒有ssed認為/<title>/是命令< (在sed中不存在)的地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM