Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次を使用して、Linux の文字列を置き換えます。
sed -i 's/old-word/new-word/g' *.txt
問題は、私の新しい単語がマクロであり、次のように定義されていることです。
d=$(date +"%Y:%m:%d")
私は次を試します:
sed -i 's/old-word/$d/g' *.txt
しかし、正しい日付の代わりに「$d」が表示されます。
これを試して:
sed -i 's/old-word/'$(date +"%Y:%m:%d")'/g' *.txt
一重引用符は変数値を展開せず、二重引用符を使用します:
sed -i "s/old-word/$d/g" *.txt
ここでマニュアルを確認してください。