Diff
字元串和文件的區別
基本上我想檢查同一文件之前和之後的差異
sed
試圖執行:
diff /opt/postTrades.sh <<< $(sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh)
和
diff <<< $(sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh) < /opt/postTrades.sh
和
diff <<< (sed 's/1\ MIN/10\ MIN/g' /opt/postTrades.sh) < /opt/postTrades.sh
總是得到:
diff: missing operand after '/opt/postTrades.sh' diff: Try 'diff --help' for more information.
正確的方法是什麼?謝謝。
diff
需要兩個文件操作數。使用here-string,您可以將輸入傳遞到diff
其標準輸入。要從
diff
標準輸入中讀取,請-
用作文件名:$ diff file - <<<"$( sed 'expression' file )"
或者,更便攜,
$ sed 'expression' file | diff file -
<(...)
如果您使用的 shell 支持使用、bash
和進行程序替換ksh93
,這可能是另一種解決方案:$ diff file <( sed 'expression' file )
程序替換將顯示為一個文件,
diff
並且實際上“相同”:$ sed 'expression' file >tempfile $ diff file tempfile $ rm tempfile