awk - awk 检查列并获取结果
问题描述
给定第一列(文件线程)的每个数量的 2 个文件 pri_seq 和 stb_seq 我必须分别在 ps 和 ss 中评估第二列,然后在 awk 工作的脚本之外产生差异,但在脚本内部却没有,好像它需要逃脱
cat pri_seq
1 656369
2 859638
cat stb_seq
1 625743
2 817088
cat threads
1
2
cat test.sh
#!/bin/sh
awk '{print $1}' pri_seq > threads
cat threads | while read line; do
ps=` awk '$1==$line {print $2}' pri_seq`;
ss=` awk '$1==$line {print $2}' stb_seq`;
echo $ps
echo $ss
# ((diff=$ps-$ss))
echo "Thread $line Sequence Primary= $ps Sequence Standby = $ss Difference = $diff"
done
它不重视 ps 和 ss
(PROD920) oracle@e812stb:/home/oracle/bin/chk_dg> ./test.sh
Thread 1 Sequence Primary= Sequence Standby = Difference =
Thread 2 Sequence Primary= Sequence Standby = Difference =
Thread Sequence Primary= Sequence Standby = Difference =
out of the script:
ps=`awk '$1==1 {print $2}' pri_seq`
echo $ps
656369
你有解决方案吗?
解决方案
你的问题不清楚,但这是你想要做的吗?
awk '
NR==FNR { ps[$1]=$2; next }
{ printf "Thread %d Sequence Primary= %d Sequence Standby= %d Difference= %d\n", $1, ps[$1], $2, ps[$1]-$2 }
' pri_seq stb_seq
Thread 1 Sequence Primary= 656369 Sequence Standby= 625743 Difference= 30626
Thread 2 Sequence Primary= 859638 Sequence Standby= 817088 Difference= 42550
推荐阅读
- python - Pandas 删除特定值
- java - Spring Batch - HibernateItemWriter:我应该输入强制转换吗?或者不需要
- apache-spark - 使用 Spark 执行增量 ETL 的最佳方法是什么?
- html - 导航菜单项未垂直居中
- c# - C# switch case 一行与fallthrough
- python - Python 中具有绝对值的 CPLEX 约束
- ios - 由于 iOS 上的白屏未捕获异常“NSInternalInconsistencyException”而终止应用程序
- sql - 在 Oracle SQL 的同一查询中使用 IN 和 NOT IN
- javascript - 如何使用 Dropzone js 显示文件的上传百分比?
- python - 使用 python 获取对 aspx 站点的 GET 请求时出现问题。“你调用的对象是空的”