LoginSignup
0
0

More than 1 year has passed since last update.

テキストファイルからN行おきに行を抽出するには

Posted at

1行目、6行目、11行目、、、のように5行おきに出力するには

$ sed -ne 1~5p < data.txt
$ awk NR%5==1 < data.txt
$ perl -nle '$.%5==1 && print' < data.txt
$ ruby -nle '$.%5==1 && print' < data.txt

5行目、10行目、15行目、、、のように5行おきに出力するには

$ sed -ne 0~5p < data.txt
$ awk NR%5==0 < data.txt
$ perl -nle '$.%5==0 && print' < data.txt
$ ruby -nle '$.%5==0 && print' < data.txt

これだけ見ると、PerlとRubyは親戚に見える。

0
0
0

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
0
0