我想通过添加两列并将一个值与另一列相加得到的结果来转换此文件。我希望这个新列位于相应的汇总列旁边。
A B C
2000 33000 2
2000 153000 1
2000 178000 1
2000 225000 1
2000 252000 1
我想获取以下数据
A A1 B B1 C
2000 2999 33000 33999 2
2000 2999 153000 153999 1
2000 2999 178000 78999 1
2000 2999 225000 225999 1
2000 2999 252000 252999 1
我找到了如何对列求和:awk '{{$2 += 999}; print $0}' myFile
但这会转换第二列,而不是创建新列。此外,我不确定如何将该列附加到所需位置。
谢谢!
最佳答案
awk '{
# increase number of columns
NF++
# shift columns right, note - from the back!
for (i = NF; i >= 2; --i) {
$(i + 1) = $i
}
# increase second column
$2 += 999
# print it
print
}
' myfile
与第 4 列类似。
https://stackoverflow.com/questions/64785472/
相关文章:
c# - 是否可以在不复制的情况下为多个组件创建一个 Blazor 范围的 CSS 文件?
javascript - Alpine JS 表格数据绑定(bind)
python - 有没有办法在 python 列表中切换元素?
reactjs - 如何模拟 JavaScript window.open 和 window.clo
perl - 可能对未定义的取消引用数组进行迭代是错误还是功能?
c# - 1053 Windows 服务错误使用 .NET Core 3.1 Worker 服务
html - React Material UI-制作一个按钮打开文件选择器窗口