0

我有一个类似的文件:

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
4

2 回答 2

3

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

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

因为你有&& < 20930000而不是&& $1 < 20930000,假设你想比较的是 $1 。

于 2013-05-07T12:12:55.390 回答
1

您的第二个脚本也缺少错误消息指向的操作数:

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

这应该是:

... || $1 > 20680000 && $1 < 20930000
于 2013-05-07T12:17:27.700 回答