-2
我正在使用awk從castep輸出文件中獲取幾行。awk輸出不能重定向到文件
forces_line = 360
no_atom = 6
如果我只需要輸入:
awk -v force_start=${forces_line} -v force_number=${no_atom} 'NR==(force_start+6), NR==(force_start+5+force_number) {print $4 " " $5 " " $6}' positive.castep
我會得到:
-0.04628 0.00040 0.00040
0.01782 0.00674 -0.00622
0.01782 -0.00622 0.00674
-0.02313 0.00622 0.00622
0.01669 -0.00372 -0.00372
0.01707 -0.00342 -0.00342
但如果我rediret結果到positive.dat文件,
awk -v force_start=${forces_line} -v force_number=${no_atom} 'NR==(force_start+6), NR==(force_start+5+force_number) {print $4 " " $5 " " $6}' positive.castep > positive.dat
positive.dat文件是空的。
會發生什麼?
你發佈的代碼並不能解釋你的症狀 - 必須有一個額外的因素。文件真的是空的嗎?請使用附加信息直接更新_您的問題,並考慮提供[MCVE(最小,完整和可驗證示例)](http://stackoverflow.com/help/mcve)。 – mklement0
它可能是您的問題的人爲因素,但請注意,您頂部的變量賦值不起作用,因爲'='字符周圍留有空白。所以也許變量永遠不會被賦值,導致'awk'註釋不能按預期工作。 – mklement0
也可以直接添加重定向...'{print $ 4「」$ 5「」$ 6>「positive.dat」}' – Sundeep