大佬教程收集整理的这篇文章主要介绍了如何在 Unix 中添加列,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在第 n 列之前添加一列:
awk 'BEGIN{FS=OFS="fs"}{$n = value OFS $n}1' filename.
我已经尝试过这个命令,但它不起作用。 “n”在这里代表什么?我是否必须将 n 更改为一个值?
我有一个包含 17 列的文件。我想在第 6 列和第 7 列之间添加一个新列。
通过在场上循环可以更好地实现这一点:
输入文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
然后在 6 和 7 之间添加“18”:
awk -F \| '{ for (i=1;i<=6;i++) { printf "%s ",$i } printf "%s","18";for (i=7;i<=$NF;i++) { printf " %s",$i } printf "\n" }' file
说明:
awk -F \| '{
for (i=1;i<=6;i++) {
printf "%s ",$i # Loop through the first 6 space delimited fields and print with a space after each one to Replicate the delimiter
}
printf "%s","18"; # Print "18" with no spaces
for (i=7;i<=NF;i++) {
printf " %s",$i # Loop through the rest of the field prinTing a space and then the field (NF - represent the last field)
}
printf "\n" # Print a new line
}' file
输出:
1 2 3 4 5 6 18 7 8 9 10 11 12 13 14 15 16 17
以上是大佬教程为你收集整理的如何在 Unix 中添加列全部内容,希望文章能够帮你解决如何在 Unix 中添加列所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。