1
我有替換字符串在另一個文件中bash腳本:awk的替換字符串中出現的所有全球
...
# make MC input script
sig=2.6
awk -v sig="$sig" '{
sub(/XSIGX/, sig);
print;
}' input.txt > output.txt
當我input.txt
運行此我得到以下爲output.txt
(通知替換爲「2.6」,但在其在cat
線缺乏):
...
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子替換一個,gsub將它們全部替換。你嘗試過gsub嗎? –
@GeorgeVasiliou我不知道gsub。謝謝你 - 如果你發佈了一個快速答案,我會接受。 – khaverim