正規表現 - タイムスタンプ後の文字列キャプチャ

正規表現 - タイムスタンプ後の文字列キャプチャ

次のタイムスタンプの後に続く文字列をキャプチャする有効な正規表現を探しています。

<38>Oct 10 14:32:29 UAT01 
<86>Oct 10 14:32:29 Test04 
<13>Oct 10 14:35:09 Dev02
<13>Oct 10 14:35:10 Test03

ベストアンサー1

質問が具体的に正規表現を要求することを考慮すると、次のようになります。

grep -Eo '\s(\w+).$' file

 UAT01 
 Test04 
 Dev02
 Test0

説明する:

`\s` matches any whitespace character.
`(\w+)` is the first Capturing Group 
 `\w+` matches any word character  and it is equal to [a-zA-Z0-9_]
 `+ ` Quantifier — Matches between one and unlimited times, as many times as possible.
 `.` matches any character (except for line terminators)
 `$` asserts position at the end of the string, or before the line terminator right at the end of the string.

cut最後の文字列は、またはを使用して簡単に抽出できます。awk

cut -d' ' -f 7 file

awk '{print $7}' file

おすすめ記事