特定の文字列を含む行のみを抽出した後、抽出された行の末尾にある数値を低い値から高い値の順にソートする方法

特定の文字列を含む行のみを抽出した後、抽出された行の末尾にある数値を低い値から高い値の順にソートする方法

次の3行の例は、次のように抽出されました。

grep  "Time to convert event = "[1-9] output.log

ただし、低い数字から高い数字にソートできる必要があります。Time to convert event = x.xxxxxx

これはどのように達成できますか?

2019-10-31 07:18:17.770 INFO [WORKER_Thread-4] [blahblah:212] [userID:] [eventID:] [objectID:] [] Time to convert event = 5.516262
2019-10-31 07:18:17.770 INFO [WORKER_Thread-4] [blahblah:212] [userID:] [eventID:] [objectID:] [] Time to convert event = 19.516262
2019-10-31 07:18:17.770 INFO [WORKER_Thread-4] [blahblah:212] [userID:] [eventID:] [objectID:] [] Time to convert event = 0.316262

ベストアンサー1

sorta)フィールド区切り記号(-t)の指定、b)フィールドによるソート-k、c)-n数値順のソートを許可します。

grep "Time to convert event = [1-9]" output.log | sort -n -t= -k2

=数字の直前に1つだけを活用する必要があります。

おすすめ記事