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.
次のような通常の値を使用する場合a=10
a=10
sedの検索/置換を機能させることができます
sed -e "s/xxx/$a/g" a.txt
しかし、私が次のような変数を使おうとするとa=http://xyz.com
a=http://xyz.com
sed -e "s/xxx/$a/g" a.txt動かない...
私が推測するそのスローする未知のオプションエラーは、変数の上に存在するエスケープ文字によるものです
これを試して:
sed -e "s@xxx@$a@g" a.txt
awkを使用すると、文字列に/、@、改行などの任意の文字を含めることができます。
$ a="http://xyz.com" $ echo "<xxx>" | awk -v a="$a" '{gsub(/xxx/,a)}1 <http://xyz.com>