最後の単語の前に(XXXX)単語を含むすべての行をキャプチャしたいです。
そしてxxxxxは数字です
/opt/OV/bin/opcagt -status
scopeux Perf Agent data collector (5102) Running
midaemon Measurement Interface daemon (5110) Running
ttd ARM registration daemon Running
perfalarm Alarm generator (5111) Running
agtrep OV Discovery Agent AGENT,AgtRep (5520) Running
coda OV Performance Core COREXT (5529) Running
opcacta OVO Action Agent AGENT,EA (5427) Running
opcle OVO Logfile Encapsulator AGENT,EA (5443) Running
opcmona OVO Monitor Agent AGENT,EA Running
opcmsga OVO Message Agent AGENT,EA (5435) Running
opcmsgi OVO Message Interceptor AGENT,EA (5553) Running
ovbbccb OV Communication Broker CORE (5352) Running
ovcd OV Control CORE (5344) Running
ovconfd OV Config and Deploy COREXT (5383) Running
私は試した
/opt/OV/bin/opcagt -status | grep [0-9]
ただし、このgrep構文は最後の単語の前の単語をキャプチャできません。
予想される結果:
scopeux Perf Agent data collector (5102) Running
midaemon Measurement Interface daemon (5110) Running
perfalarm Alarm generator (5111) Running
agtrep OV Discovery Agent AGENT,AgtRep (5520) Running
coda OV Performance Core COREXT (5529) Running
opcacta OVO Action Agent AGENT,EA (5427) Running
opcle OVO Logfile Encapsulator AGENT,EA (5443) Running
opcmsga OVO Message Agent AGENT,EA (5435) Running
opcmsgi OVO Message Interceptor AGENT,EA (5553) Running
ovbbccb OV Communication Broker CORE (5352) Running
ovcd OV Control CORE (5344) Running
ovconfd OV Config and Deploy COREXT (5383) Running
答え1
(4-digits)<spaces>word
行の末尾にパターンを含む行を検索する
grep -E '\([0-9]{4}\)\s*\w+$'
答え2
努力する
/opt/OV/bin/opcagt -status | awk 'NF>2 && $(NF-1) ~ /\([0-9]*\)/ '
どこ
$(NF-1)
最後のフィールドの前の一致~
awkにパターンマッチングをさせる/\([0-0]*\)/
パターンは、(
任意の数の数字と)
([0-9] [0-9] *を使用して少なくとも1つを取得できます)。- デフォルトのジョブは印刷です。
答え3
あなたはできます:
... | grep -E '[[:blank:]]\([0-9]{4}\)[[:blank:]]+[^[[:blank:]]+$'
[[:blank:]]\([0-9]{4}\)
スペースの後に4桁の数字が続くものと一致します。[[:blank:]]+[^[[:blank:]]+$
末尾の 1 つ以上の空白と、その後に空白以外の文字が 1 つ以上一致します。
例:
$ cat file.txt
scopeux Perf Agent data collector (5102) Running
midaemon Measurement Interface daemon (5110) Running
ttd ARM registration daemon Running
perfalarm Alarm generator (5111) Running
agtrep OV Discovery Agent AGENT,AgtRep (5520) Running
coda OV Performance Core COREXT (5529) Running
opcacta OVO Action Agent AGENT,EA (5427) Running
opcle OVO Logfile Encapsulator AGENT,EA (5443) Running
opcmona OVO Monitor Agent AGENT,EA Running
opcmsga OVO Message Agent AGENT,EA (5435) Running
opcmsgi OVO Message Interceptor AGENT,EA (5553) Running
ovbbccb OV Communication Broker CORE (5352) Running
ovcd OV Control CORE (5344) Running
ovconfd OV Config and Deploy COREXT (5383) Running
$ grep -E '[[:blank:]]\([0-9]{4}\)[[:blank:]]+[^[[:blank:]]+$' file.txt
scopeux Perf Agent data collector (5102) Running
midaemon Measurement Interface daemon (5110) Running
perfalarm Alarm generator (5111) Running
agtrep OV Discovery Agent AGENT,AgtRep (5520) Running
coda OV Performance Core COREXT (5529) Running
opcacta OVO Action Agent AGENT,EA (5427) Running
opcle OVO Logfile Encapsulator AGENT,EA (5443) Running
opcmsga OVO Message Agent AGENT,EA (5435) Running
opcmsgi OVO Message Interceptor AGENT,EA (5553) Running
ovbbccb OV Communication Broker CORE (5352) Running
ovcd OV Control CORE (5344) Running
ovconfd OV Config and Deploy COREXT (5383) Running