1
を文字列の出現をすべて置き換える:awkの私は別のファイルに文字列を代入しbashスクリプトを持っているグローバル
...
# make MC input script
sig=2.6
awk -v sig="$sig" '{
sub(/XSIGX/, sig);
print;
}' input.txt > output.txt
私はinput.txt
でこれを実行すると、私は「2.6」としてoutput.txt
(通知代替品として、以下を得るが、 cat
ラインにおけるその欠如):AWK関数sub
で
...
echo "hi" >> /work/d/dfranz/o2_modeling/simulated_densities_2.6.txt
cat /work/d/dfranz/o2_modeling/simulated_densities_2.6.txt | sort -nk1 > /work/d/dfranz/o2_modeling/simulated_rho_sorted_XSIGX.txt # <--- This XSIGX was not replaced but the first occurrence in this line was
rm /work/d/dfranz/o2_modeling/simulated_densities_2.6.txt
AFAIK subは1つを置き換え、gsubはそれらをすべて置き換えます。あなたはgsubを試しましたか? –
@GeorgeVasiliou私はgsubについて知らなかった。親切にありがとうございます。あなたが迅速な回答を投稿すれば、私は同意します。 – khaverim