LoginSignup
4
2

More than 5 years have passed since last update.

【Bash】ファイルの中身をN行おきに出力する

Last updated at Posted at 2016-10-01

awk 'NR%N==0' hoge.txt
※Nには任意の数字が入る。

1から10までの数字が書き込まれているファイルがあるとする。

number.txt
1
2
3
4
5
6
7
8
9
10
awk 'NR%2==0' number.txt
# => 2, 4, 6, 8, 10
awk 'NR%3==0' number.txt
# => 3, 6, 9
awk 'NR%4==0' number.txt
# => 4, 8
awk 'NR%5==0' number.txt
# => 5, 10
4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2