0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ファイルの特定行を抜き出してソートした結果を取得

Last updated at Posted at 2022-03-11

catでファイルを読み込んで、sedで行数指定して取得。その結果をsortする。

例、 ファイルの10行目〜20行目をソートする

cat hoge.txt | sed -n '10,20p' | sort -f -d

sedの部分を変更すれば行数指定以外のやり方もできる。

sortコマンドのパラメータについて補足

  • -f 大文字/小文字を区別しない
  • -d データが空白と英数位のみ含まれていると仮定して並び替える
    • どういうアルゴリズムか知らないが、これをつけないと""で囲った中身がアルファベット順にソートされない

余談

Pipfileの[packages]に指定したモジュールの並びがばらばらだったので並び替えたかった

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?