パターン内で文字列を検索するコマンド

パターン内で文字列を検索するコマンド

ログファイルの内容は次のとおりです。

Caused by: com.ofss.fc.framework.exception.BusinessException: The memo start date cannot be earlier than the process date.
at com.ofss.fc.domain.party.service.core.CommentService.validateMemos(CommentService.java:474)
at com.ofss.fc.lz.us.appx.party.service.core.ext.RegionalPartyAddressApplicationServiceSpiExt.preUpdatePartyAddress(RegionalPartyAddressApplicationServiceSpiExt.java:43)
at com.ofss.fc.appx.party.service.core.ext.PartyAddressApplicationServiceSpiExtExecutor.preUpdatePartyAddress(PartyAddressApplicationServiceSpiExtExecutor.java:82)
at com.ofss.fc.appx.party.service.core.PartyAddressApplicationServiceSpi.updatePartyAddress(PartyAddressApplicationServiceSpi.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Caused by: com.ofss.fc.framework.exception.BusinessException: The memo start date cannot be earlier than the process date.
at com.ofss.fc.domain.party.service.core.CommentService.validateMemos(TestService.java:474)
at com.ofss.fc.lz.us.appx.party.service.core.ext.RegionalPartyAddressApplicationServiceSpiExt.preUpdatePartyAddress(RegionalPartyAddressApplicationServiceSpiExt.java:43)
at com.ofss.fc.appx.party.service.core.ext.PartyAddressApplicationServiceSpiExtExecutor.preUpdatePartyAddress(PartyAddressApplicationServiceSpiExtExecutor.java:82)
at com.ofss.fc.appx.party.service.core.PartyAddressApplicationServiceSpi.updatePartyAddress(PartyAddressApplicationServiceSpi.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Caused次の行をキャッチしようとしています

bash-4.1$ a=$(awk '/Caused/{getline; print}' testError.log )
bash-4.1$ echo $a

出力:

com.ofss.fc.domain.party.service.core.CommentService.validateMemos(CommentService.java:474) at com.ofss.fc.domain.party.service.core.CommentService.validateMemos(TestService.java:474)

()内のすべてのファイル名をリストする必要があります。

リストの出力は次のようになります。

CommentService.java
TestService.java

答え1

そしてsed

$ sed -n '/Caused/{
  N
  s/.*\n[^(]*(//
  s/:[^:]*$//
  p
}' <file

答え2

grepJavaファイル名が文字、数字、_でのみ構成されていると仮定してを使用してください。

awk '/Caused/{getline; print}' testError.log | grep -oE '\w+\.java'

sed一般ファイル名の場合

awk '/Caused/{getline; print}' testError.log | sed -r 's/.*\((.*):.*/\1/'

答え3

同居するawk

awk '/Caused/{getline; match($0, /[^(]*\.java/); 
     if (RSTART)print(substr($0, RSTART, RLENGTH))}' file

関連情報