我想使用AWK仅更改文本文件的特定值,并保留其余的值。
输入文件 ene.txt:
energy_of_node 1 48.03004556
energy_of_node 2 56.05655687
energy_of_node 3 48.03004556
energy_of_node 4 56.05655687
energy_of_node 5 48.03004556
energy_of_node 6 56.05655687
energy_of_node 7 48.03004556
energy_of_node 8 56.05655687
我需要更改由TCL提供的变量值。
my_code.tcl:
to_node = 7
exec awk -f drain.awk -v var=$to_node ene.txt
drain.awk:
#Here I need to alter the value of var to 0.000100
BEGIN{} {
if($2 == var) {
$3==0.000100
# but this definitely will not work, since this changes the entire file.
}
}
END {
}