2022年9月12日星期一

linux grep output group capture

grep can't output all group captures after one grep action.

so. each grep a time. 

ex.

input_string= "Caused by: java.io.FileNotFoundException: /tmp/storage/imart/public/storage/default/im_workflow/data/default/transaction/202107/21/16/ma_8g2mm9ovekgierj/result/ep_8g2mo7z76kgrmrj/flow.xml (No such file or directory)"

#I want to get
#[1]=/tmp/storage/imart/public/storage/default/im_workflow/data/default/transaction
#[2]=202107/21/16/
#[3]=ma_8g2mm9ovekgierj
#[4]=ep_8g2mo7z76kgrmrj

#cmd:
a1=$(echo $input_string | grep -ioE  "/tmp/.+/transaction")
echo $a1
:/tmp/storage/imart/public/storage/default/im_workflow/data/default/transaction

a2=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}")
echo $a2
=> 202107/21/16

a3=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}/\w+" | grep -ioE "\w+$")
echo $a3
:ma_8g2mm9ovekgierj

a4=$(echo $input_string | grep -ioE "\w+/flow" | grep -ioE "^\w+")
echo $a4
:ep_8g2mo7z76kgrmrj

$ echo $input_string | grep -ioE  "/tmp/.+/transaction"


log=webapps/imart/WEB-INF/log/platform/
found=$(find $log -type f -name "*.log"  | xargs grep -ionE "Caused by: java.io.FileNotFoundException:.+" )
for input_string in $(find $log -type f -name "*.log" | xargs grep -ionE "Caused by: java.io.FileNotFoundException:.+" )
do
  a1=$(echo $input_string | grep -ioE  "/tmp/.+/transaction")
  a2=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}")
  a3=$(echo $input_string | grep -ioE "[0-9]{6}/[0-9]{2}/[0-9]{2}/\w+" | grep -ioE "\w+$")
  a4=$(echo $input_string | grep -ioE "\w+/flow" | grep -ioE "^\w+")
  echo a1=$a1,a2=$a2,a3=$a3,a4=$a4
done 


没有评论: