2016-06-28 18 views

回答

1

你只需要逃避目前的斜線。下面的例子中GNU sed version 4.2.1

$ echo "some text \u2015 some more text" | sed -e "s/some text \\\u2015 some more text/abc/" 
$ abc 

工作正常,你也不必使用-i標誌根據該man網頁,其中僅用於就地編輯files

-i[SUFFIX], --in-place[=SUFFIX] 

    edit files in place (makes backup if extension supplied). The default operation mode is to break symbolic and hard links. This can be changed with --follow-symlinks and 
      --copy. 
+1

切勿在腳本週圍使用雙引號,始終使用單引號。在這種情況下,如果你這樣做,你會發現你並不需要那麼多逃脫。 –

-1

不知道這是否是你所需要的東西,但也許你應該看看native2ascii工具,例如Unicode轉義轉換。

正常情況下,它會用Unicode替換所有無法在ISO-8859-1中顯示的字符(用\ u轉義),但它也支持反向轉換。假設你在UTF-8命名爲「輸入」含\u00abSome \u2015 string\u00bb一些文件,然後執行

native2ascii -encoding UTF-8 -reverse input output 

將導致與«Some ― string»「產出」的文件。

相關問題