ファイルの先頭にこれを追加できます。
sed -i '1s/^/word\n/' file
はい読む二重引用符を使用すると変数を拡張できるため、次のことを試してください。
sed -i "1s/^/$(printenv)\n/" file
私は最終的に戻った:
sed: -e expression #1, char 15: unterminated `s' command
どうしたの?変数の内容やその他に関連していますか?
ベストアンサー1
私は次のことがうまくいくと思います。
sed -i '1 e printenv' file
GNU sedマニュアルから:
'e COMMAND'
Executes COMMAND and sends its output to the output stream. The
command can run across multiple lines, all but the last ending with
a back-slash.
または を使用できますが、cat
これを行うには一時ファイルを作成する必要があります。
cat <(printenv) file > temporary_file; mv temporary_file file
パッケージがコンピュータにインストールされている場合は、moreutils
次のコマンドを使用して一時ファイルを手動で作成するのを防ぎますsponge
。
cat <(printenv) file | sponge file