由於這是問題有一個UNIX標籤:
grep -P "baseFileName=([^,]+),.*,\1" test.txt
說明:
baseFileName=([^,]+) # first pair of parentheses gives you baseFilename
,.*, # read ',' followed by anything, followed by ','
\1 # backreference to baseFilename
測試:
$ cat test.txt
2017-06-19 21:54:11,773 mimeType=docx,baseFileName=TEST
boo.docx,fileNamePrefix=7ff852cb-b1db-49d3-ba71-
e151dbc1f41e,doEncrypt=true,decryptedFileSize=125589,Test foo-boo.docx
[source:MessageConsumer]
2017-06-19 21:54:11,774 mimeType=docx,baseFileName=TEST
foo.docx,fileNamePrefix=7ff852cb-b1db-49d3-ba71-
e151dbc1f41e,doEncrypt=true,decryptedFileSize=125589,TEST foo.docx
[source:MessageConsumer]
2017-06-19 21:54:11,774
mimeType=docx,baseFileName=aaa.docx,fileNamePrefix=7ff852cb-b1db-49d3-
ba71-e151dbc1f41e,doEncrypt=true,decryptedFileSize=125589,aaa.docx
[source:MessageConsumer]
$ grep -P "baseFileName=([^,]+),.*,\1" test.txt
2017-06-19 21:54:11,774 mimeType=docx,baseFileName=TEST
foo.docx,fileNamePrefix=7ff852cb-b1db-49d3-ba71-
e151dbc1f41e,doEncrypt=true,decryptedFileSize=125589,TEST foo.docx
[source:MessageConsumer]
2017-06-19 21:54:11,774
mimeType=docx,baseFileName=aaa.docx,fileNamePrefix=7ff852cb-b1db-49d3-
ba71-e151dbc1f41e,doEncrypt=true,decryptedFileSize=125589,aaa.docx
[source:MessageConsumer]
你說的「我的文件名是什麼意思「? – batMan