ファイルに次の行があることを確認したいと思います。
/var/log/report
{
<any string>
最初の行は - /var/log/reports
第二 -{
第三 - 何でも単語/文字列(A-Za-z)
したがって、発生するすべての行の出力にOKが表示され、一致する行があります。
/var/log/report
{
<any string>
はい
# Un-comment the following to provide a specific roving profile share.
# The default is to use the user's home directory:
; [Profiles]
; path = /var/lib/samba/profiles
; browseable = no
; guest ok = yes
/var/log/report
{
fkergfve
# A publicly accessible directory that is read only, except for users in the
# "staff" group (which have write permissions):
; [public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = +staff
/var/log/report
{
kfreve
# "staff" group (which have write permissions):
; [public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = +staff
/var/log/report
{
jdhe
期待される出力
OK
/var/log/report
{
fkergfve
OK
/var/log/report
{
kfreve
OK
/var/log/report
{
jdhe
ベストアンサー1
Awk
回避策(キーパターン行の厳密な順序と書式設定):
awk 'NF == 1{
if (f) {
if (NR-n == 1 && $1 == "{")
r = r ORS $0;
else if (NR-n == 2 && $0 ~ /[a-zA-Z]+/)
print "OK" ORS r ORS $0;
}
if ($1 == "/var/log/report") {
f = 1; n = NR; r = $0
}
}n && NR-n > 2{ f = 0 }' file
出力:
OK
/var/log/report
{
fkergfve
OK
/var/log/report
{
kfreve
OK
/var/log/report
{
jdhe