如何打印特定列但忽略unix shell中的前10行和最后10行

时间:2015-03-27 05:57:42

标签: shell unix

我想要打印第二列,但我不想要前10行和后10行。

 awk 'NR>10' filename.txt | awk '{ print $2 }'| head --lines=-10

它对我不起作用

1 个答案:

答案 0 :(得分:1)

你想要的是:

tail -n+11 filename.txt | head -n-10 | awk '{print $2}'

<强>输入

$cat lines_1-40.txt
line 1 in the file
line 2 in the file
line 3 in the file
line 4 in the file
...
line 38 in the file
line 39 in the file
line 40 in the file

<强>输出

$ tail -n+11 lines_1-40.txt | head -n-10 | awk '{print $2}'
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30