这可以是一种方法:
awk -F, '{for (i=1; i<=NF/2; i++) printf "%s, ", $i} <-- prints first half
{printf "\n"} <--- prints new line
{for (i=NF/2+1; i<=NF; i++) printf "%s, ", $i} <-- prints second half
{printf "\n"} <--- prints new line
'
测试
$ awk -F, '{for (i=1; i<=NF/2; i++) printf "%s, ", $i} {printf "\n"} {for (i=NF/2+1; i<=NF; i++) printf "%s, ", $i} {printf "\n"}' <<< "server_0.example.com, server_1.example.com, ..., server_70.example.com"
server_0.example.com, server_1.example.com,
..., server_70.example.com,
更新
当 NF 为奇数时不跳过一个值:
awk -F, '{for (i=1; i<=int(NF/2); i++) printf "%s, ", $i} <-- prints first half
{printf "\n"} <--- prints new line
{for (i=int(NF/2)+1; i<=NF; i++) printf "%s, ", $i} <-- prints second half
{printf "\n"} <--- prints new line
'