마지막 단어 앞에 (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]*를 사용하여 최소한 하나를 얻을 수 있습니다.- 기본 작업은 인쇄입니다.
답변3
넌 할 수있어:
... | grep -E '[[:blank:]]\([0-9]{4}\)[[:blank:]]+[^[[:blank:]]+$'
[[:blank:]]\([0-9]{4}\)
공백 뒤에 4자리 숫자가 오는 것과 일치합니다.[[:blank:]]+[^[[:blank:]]+$
끝 부분에서 하나 이상의 공백과 그 뒤에 공백이 아닌 문자가 하나 이상 일치합니다.
예:
$ 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