【问题标题】:Concatenate a string and an integer and assign it to a new column连接字符串和整数并将其分配给新列
【发布时间】:2013-06-04 20:59:36
【问题描述】:

代码(AWK 脚本):

for(i=0; i<numColumns; ++i){

$(NF+i)="group" #This will print group, but I want to print 
#group1, group2, group3 and so on...
#In other words, i want something like $(NF+i)="group".$i so that 
#the output is group1, group2....

    }

我将这些词添加到新列中,因此是 (NF+i)。

我的问题是如何连接,以便我可以打印 group1、group2 等。 我可以使用 print 命令执行此操作,但我想将其分配给列 NF+i。

【问题讨论】:

  • 您可以使用带有数字索引的group 数组吗?

标签: awk


【解决方案1】:

try:(打印语句省略)

for(i=0; i<numColumns; ++i){

$(NF+i)="group " i


    }

【讨论】:

  • 为什么每次打印后空格都会增加?我的代码是$(NF+i)="group"i 并打印出group1 group2 group3 等,但每次打印后多了一个空格
猜你喜欢
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-09
  • 1970-01-01
  • 2013-05-09
相关资源
最近更新 更多