1、创建测试数据

[root@linuxprobe test]# seq 20 > a.txt
[root@linuxprobe test]# ls
a.txt
[root@linuxprobe test]# head a.txt
1
2
3
4
5
6
7
8
9
10

 

2、提取奇数行

[root@linuxprobe test]# awk 'NR%2 != 0' a.txt
1
3
5
7
9
11
13
15
17
19

 

3、提取偶数行

[root@linuxprobe test]# awk 'NR%2 == 0' a.txt
2
4
6
8
10
12
14
16
18
20

 

4、提取非三倍数行

[root@linuxprobe test]# awk 'NR%3 != 0' a.txt
1
2
4
5
7
8
10
11
13
14
16
17
19
20

 

5、提取三倍数行

[root@linuxprobe test]# awk 'NR%3 == 0' a.txt
3
6
9
12
15
18

其余以此类推。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
相关资源
相似解决方案