在米勒的数据字段中输出标题标签

agc*_*agc 5 text-processing miller

给定file.csv

a,b,c
1,2,3
Run Code Online (Sandbox Code Playgroud)

如何mlr输出:

a,b,c
1,2,c
Run Code Online (Sandbox Code Playgroud)

使用预先$c 知道$c包含字母“ c ”的标签名称?


注意:正确答案mlr只能使用。

abo*_*uso 5

编辑答案

你好,你可以使用这个脚本

mlr --csv put 'if (NR == 1) {
counter=1;
  for (key in $*) {
    if (counter == 3) {
    $[key]=key;
    }
    counter += 1;
  }
}' input.csv
Run Code Online (Sandbox Code Playgroud)

作为输出,您将拥有:

a,b,c
1,2,c
Run Code Online (Sandbox Code Playgroud)

NR == 1获得第一行,并counter == 3获得第三个字段。