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?

ログからURLの一部だけ抽出してリアルタイムに出力(重複除去&ソート)

0
Last updated at Posted at 2025-05-22

以下のようなパイプラインで実現できます。

重複除去・ソートする場合

grep '/api/v1/' \
  | awk 'match($0, /\/api\/v1\/([^\/]+)/, m) { print m[1] }' \
  | sort -u

ファイルの末尾100行に限定したい場合は、先頭に tail -n 100 を追加

tail -n 100 your.log \
  | grep '/api/v1/' \
  | awk 'match($0, /\/api\/v1\/([^\/]+)/, m) { print m[1] }' \
  | sort -u

PowerShell でやる場合

PowerShell は Linux のようなワンライナー処理には向きませんが、以下のようにすれば似たことができます:

Get-Content .\your.log |
  Select-String '/api/v1/' |
  ForEach-Object {
    if ($_ -match '/api/v1/([^/]+)') {
      $matches[1]
    }
  } | Sort-Object -Unique
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?