shell - awk 中的管道如何工作(保留标头排序)
问题描述
下面的命令输出一个文件的头部并且在头部之后对记录进行排序。但它是如何工作的?谁能解释一下这个命令?
awk 'NR == 1; NR > 1 {print $0 | "sort -k3"}'
解决方案
请您看一遍(仅用于解释目的)。为了学习更多的概念,awk
我建议通过Stack Overflow 不错的 awk 学习部分
awk ' ##Starting awk program from here.
NR == 1; ##Checking if line is first line then print it.
##awk works on method of condition then action since here is NO ACTION mentioned so by default printing of current line will happen
NR > 1{ ##If line is more than 1st line then do following.
print $0 | "sort -k3" ##It will be keep printing lines into memory and before printing it will sort them with their 3rd field.
}'
推荐阅读
- sql - 如果 CSV 没有所有表格字段,如何将 CSV 导入表格?
- javascript - React 中的 PrivateRouter 组件
- apache-kafka-streams - 如何为spring kafka流中的多个绑定设置UncaughtExceptionHandlers?
- python - 如何显式查找构建的 Tensorflow 模型并提取模型预测
- google-apps-script - 如何在 AppMaker 的 MultiSelect 小部件中手动设置值?
- python - 如何在我的项目中正确加载 Python 类?
- r - 如何使用 Slurm 在多个节点上发送循环?
- excel - 如何按单独的列有条件地排序?
- java - 在Java中以O(N)而不是O(NlogN)构建堆
- sql - 嵌套事务找不到保存点