grep通常只搜索單行模式,除非您在gnu grep中使用-z選項。 您可以嘗試此gnu awk命令: awk -v RS='(^|\n){[^}]+?sync.out.notify.job.status[^}]+}(\n|$)' 'RT {printf "%s", RT}' file{ "cloudid": "00000000-0000-0000-0000-000000000000", "job": "files", "majorstate": "syncing", "minorstate": "transferring", "requestid": "45768456-bd58-4cb5-9dff-dfgjfgdj456", "type": "sync.out.notify.job.status", "userid": "XXXXXXXXXXXXXXXXXXXXXXXX@AdobeID", "version": "1.1.43711"}{ "errors": "", "cloudid": "00000000-0000-0000-0000-000000000000", "job": "files", "majorstate": "idle", "minorstate": "complete", "requestid": "4856658fdgh-efb3-4da9-b5f5-48