请教关于awk的一个循环问题(已完成)
发表于 : 2012-12-14 19:38
有一个qhost.e的文件,内容如下,
HOSTNAME ARCH NCPU LOAD MEMTOT MEMUSE SWAPTO SWAPUS
-------------------------------------------------------------------------------
global - - - - - - -
compute-0-0 lx26-amd64 4 4.68 3.9G 3.5G 4.0G 2.9G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
6 0.50500 test1.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
7 0.60500 test4.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
all.q@comp SLAVE
compute-0-1 lx26-amd64 4 3.26 3.9G 4.2G 4.0G 3.1G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
8 0.60500 test2.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
9 0.60500 test3.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
compute-0-2 lx26-amd64 4 - 4.1G - 4.0G -
compute-0-3 lx26-amd64 4 0.03 3.9G 2.3G 4.0G 0.0
compute-0-4 lx26-amd64 12 1.02 3.9G 1.5G 4.0G 0.0
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
10 0.50500 test1.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
想通过awk处理一个循环,当i=1输出,
compute-0-0 lx26-amd64 4 4.68 3.9G 3.5G 4.0G 2.9G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
6 0.50500 test1.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
7 0.60500 test4.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
all.q@comp SLAVE
当i=2输出,
compute-0-1 lx26-amd64 4 3.26 3.9G 4.2G 4.0G 3.1G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
8 0.60500 test2.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
9 0.60500 test3.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
以此类推;
现在我通过shell和awk混合可以做到,
for ((m=1; m<=4; m++)) # m is the number of your compute nodes
do # Get the special node iformation from the cycle
cat qhost.e |sed 1,3d |awk 'BEGIN{node=0} /lx26-/{node+=1} {if(node=="'"$m"'")print}' |awk '
-----中间还要做一些其他处理----
'
done
但是这样混合效率并不高,每次要shell循环一次,awk才提取数据;如果能用awk直接循环效率应该很高
我尝试了下,用cat qhost.e |sed 1,3d |awk 'BEGIN{node=0} /lx26-/{node+=1} {for (i=1; i<=node; i++) {
-----中间还要做一些其他处理----}
}'
但这么处理总出差。
哪位高人能否指点一下,谢谢!
HOSTNAME ARCH NCPU LOAD MEMTOT MEMUSE SWAPTO SWAPUS
-------------------------------------------------------------------------------
global - - - - - - -
compute-0-0 lx26-amd64 4 4.68 3.9G 3.5G 4.0G 2.9G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
6 0.50500 test1.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
7 0.60500 test4.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
all.q@comp SLAVE
compute-0-1 lx26-amd64 4 3.26 3.9G 4.2G 4.0G 3.1G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
8 0.60500 test2.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
9 0.60500 test3.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
compute-0-2 lx26-amd64 4 - 4.1G - 4.0G -
compute-0-3 lx26-amd64 4 0.03 3.9G 2.3G 4.0G 0.0
compute-0-4 lx26-amd64 12 1.02 3.9G 1.5G 4.0G 0.0
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
10 0.50500 test1.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
想通过awk处理一个循环,当i=1输出,
compute-0-0 lx26-amd64 4 4.68 3.9G 3.5G 4.0G 2.9G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
6 0.50500 test1.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
7 0.60500 test4.sh wuy r 12/09/2012 14:47:26 all.q@comp MASTER
all.q@comp SLAVE
当i=2输出,
compute-0-1 lx26-amd64 4 3.26 3.9G 4.2G 4.0G 3.1G
job-ID prior name user state submit/start at queue master ja-task-ID
----------------------------------------------------------------------------------------------
8 0.60500 test2.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
9 0.60500 test3.sh tester r 12/09/2012 14:48:52 all.q@comp MASTER
all.q@comp SLAVE
以此类推;
现在我通过shell和awk混合可以做到,
for ((m=1; m<=4; m++)) # m is the number of your compute nodes
do # Get the special node iformation from the cycle
cat qhost.e |sed 1,3d |awk 'BEGIN{node=0} /lx26-/{node+=1} {if(node=="'"$m"'")print}' |awk '
-----中间还要做一些其他处理----
'
done
但是这样混合效率并不高,每次要shell循环一次,awk才提取数据;如果能用awk直接循环效率应该很高
我尝试了下,用cat qhost.e |sed 1,3d |awk 'BEGIN{node=0} /lx26-/{node+=1} {for (i=1; i<=node; i++) {
-----中间还要做一些其他处理----}
}'
但这么处理总出差。
哪位高人能否指点一下,谢谢!