file - awk 比较同一文件的两列并在新列中打印输出
问题描述
我正在尝试比较 txt 文件中两列的值,以确定第一列的值是否比第二列的值大,并且我希望第三列说“这里是主要的”或“这里少了”。
这里有一个例子:
col 1 col 2
0.19727856043434921 0.3970115896012234
0.23832706720231472 0.25380634765625
0.12105356101624322 0.3748512347530257
0.28048626091230955 0.05645118584277009
我想要类似的东西
col 1 col 2
0.19727856043434921 0.3970115896012234 here is less
0.23832706720231472 0.25380634765625 here is less
0.12105356101624322 0.3748512347530257 here is less
0.28048626091230955 0.05645118584277009 here is major
我尝试如下使用 awk 但没有检测到真相
awk 'OFS="\t" {if( $1>$2) print "here is major"; else if( $1<$2) print "here is less"} ' file.txt > file2.txt
解决方案
推荐阅读
- python - 没有这样的元素:无法定位元素(使用隐式等待后)
- github - AsciiDoc:如何在 github 风格的 asciidoc 中嵌入 youtube 视频?
- typo3 - TYPO3 TypoScript CONTENT 如何呈现选择结果
- ios - 预览包装到 SwiftUI 的 UIView 的不同语言环境
- python - 从 tempfile.TemporaryFile 写入和读取音频
- c - C 中来自 .txt 的 Fscanf
- python - TensorFlow 2 AttributeError:“元组”对象没有属性“层”
- python - sklearn - knn 值错误:预期的二维数组
- ruby-on-rails - 在这种情况下如何避免双重渲染?
- azure - 如何将 Json 变量传递给 Azure DevOps 管道中的命令行任务?