bash - 在比较列时打印具有差异的整行
问题描述
我想打印值不匹配的整行
例如:
Symbol Qty Symbol Qty Symbol qty
a 10 a 10 a 11
b 11 b 11 b 11
c 12 c 12 f 13
f 12 f 12 g 13
输出 :
a 10 a 10 a 11
c 12 c 12 (empty Space)
f 12 f 12 f 13
empty space {ES} g 13
awk 'FNR==NR{a[$0];next}!($0 in a ) ' output1.csv output2.csv >> finn1.csv
awk 'FNR==NR{a[$0];next}!($0 in a ) ' finn1.csv output4.csv >> finn.csv
但这会打印在一列中,就像 11 一样,但我需要整行
解决方案
假设您只想测试不匹配的Qty
字段,请尝试以下操作:
#!/bin/bash
declare input_file="/path/to/input_file"
declare -i header_flag=0 a b c
while read line; do
[ ${header_flag} -eq 0 ] && header_flag=1 && continue # Ignore first line.
[ ${#line} -eq 0 ] && continue # Ignore blank lines.
read x a x b x c x <<< ${line} # Reuse ${x} because it is not used.
[ ${a} -ne ${b} -o ${a} -ne ${c} -o ${b} -ne ${c} ] && echo ${line}
done < ${input_file}
推荐阅读
- reactjs - 如何将变量导出到另一个文件 React
- ios - 并发限制 PanGestureRecognizer - Swift - 以编程方式
- javascript - 当我使用 react.js 进行 API 请求时,为什么我会收到来自 unsplash.com 的 401 Unauthorized 响应?
- json - 如何按值返回特定的 JSON 对象
- javascript - 我应该在一个只调用一个已经在其主体中使用 try 和 catch 的函数的函数中捕获错误吗?
- php - For-Loop中的PHP CURL请求真的很慢
- typescript - Vue 3 Typescript 不可分配给类型“[]”
- oracle - 我如何通过 LKM ODI12c(oracle 数据集成器)中的 getcollist() 方法订购表达式
- python - 如何将字典中的两个值映射到单个字典中?
- python - 如何在 Scrapy 中修改链接