I have a script that returns strings of the form -
http-STYPE-CONNECT-new/mydir/20200215_14-30-01/http/PAY_STYPE-CONNECT-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
http-PARALLEL-new/mydir/20200215_14-30-01/http/PAY_PARALLEL-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
http-STYPE-new/mydir/20200215_14-30-01/http/PAY_STYPE-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
http-STYPE-CONNECT-0RTT-new/mydir/20200215_14-30-01/http/PAY_STYPE-CONNECT-0RTT-new/ "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
I would like to split (or apply regex) each string in such a way that everything before the first '/' is stored into variable test_name
, everything between the first '/' and last '/' of the path is stored in variable path
and everything after the last '/' of the path is stored in the variable failure_reason
.
Example:
test_name = http-STYPE-CONNECT-new
path = /mydir/20200215_14-30-01/http/PAY_STYPE-CONNECT-new/
failure_reason = "Check for atleast one http 200": Expression '($1=="r" && $13==200)' matched 0 time(s), which is below specified min of 1
There are two other possibilities that could make the parsing complex -
- There could be a
\n
anywhere between the string. For example: after the last '/' of the path. - There can be a '/' in the string that could appear after the last '/' of the path.
I simply tried using the split('/'), join(), strip()
functions in python3, but couldn't really manage to get what I wanted to achieve.