linux - 值之间的 Awk 线

标签 linux unix awk gawk

我有一个类似的 infile:

1 And finally, monsieur, a wafer-thin mint.
2 Nah.
3 Oh, sir, it's only a tiny, little, thin one.
4 No. ****** off. I'm full.
5 Oh, sir. Hmm? It's only wafer thin.
6 Look. I couldn't eat another thing. I'm absolutely stuffed. Bugger off.
7 Oh, sir, just-- just one.
8 All right. Just one. 
9 Just the one, monsieur. Voilà.

命令:

awk '$1 >1 && $1 < 4 || $1 > 5 && $1 < 8' infile

这应该给我

2 Nah.
3 Oh, sir, it's only a tiny, little, thin one.
6 Look. I couldn't eat another thing. I'm absolutely stuffed. Bugger off.
7 Oh, sir, just-- just one.

所以这个例子有效。但是这个命令:

awk '$1 > 10510000 && $1 < 12390000 || $1 < 2709520 || $1 > 57443438 || $1 > 20680000 && < 20930000'

给我这个:

awk: $1 > 10510000 && $1 < 12390000 || $1 < 2709520 || $1 > 57443438 || $1 > 20680000 && < 20930000
awk:                                                                                     ^ syntax error

最佳答案

您发布的脚本在错误消息指示的位置存在语法错误:

awk: $1 > 10510000 && ... || $1 > 20680000 && < 20930000
awk:                                          ^ syntax error

因为你有 && < 20930000而不是 && $1 < 20930000 ,假设您要比较的是 1 美元。

关于linux - 值之间的 Awk 线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16418069/

相关文章:

linux - 如何在 shell 脚本中打印格式化为 cat 命令的 echo 语句?

awk - AWK中管道的使用

bash:模式 x 和 y 之间的单独行 block

bash - 删除模式前的所有内容

mysql - 终止了 Amazon Linux 中的 'mysqld' 进程 - 一切似乎都正常,真的吗?

linux - 重新格式化 ini 字符串

linux - 了解 linux 或 BSD 内核内部结构的最佳方式是什么?

c - h_errno 总是打印 "unknown host"

linux - linux 适合编程吗?

linux - 查找文件名中没有空格的文件