Regular expression help

C

cyberphoo

I would like to catch the following pattern:

A substring in the file beginning with the pattern "Importing file" and
ending with the pattern "Modified.*rows in.*table", possibly spanning
multiple lines provided that it contains the string Exception. The
substring should not contain the beginning or ending patterns more than
once...

The following command almost works, except that it may return strings
that contain "Importing file" multiple times:

perl -0777ne "print m!Importing
file[\s\S]*?Exception[\s\S]*?Modified.*table!g;" test.txt

Does anyone know what changes I could make to the regular expression so
that it returns the correct pattern?

Below is a sample document:

<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-AC_VIOLATION.xml]]></message>
<message priority="info"><![CDATA[7047 [main] INFO
com.workbrain.util.DataLoader - Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-DOCKET.xml]]></message>
<message priority="info"><![CDATA[7110 [main] INFO
com.workbrain.util.DataLoader - Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-SHIFT.xml]]></message>
<message priority="info"><![CDATA[7266 [main] INFO
com.workbrain.util.DataLoader - Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-TIME_CODE.xml]]></message>
<message priority="info"><![CDATA[7469 [main] WARN
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement - Commit timeout
or other SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[Commit timeout or other
SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[7469 [main] ERROR
com.workbrain.util.RowPersister - On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[7500 [main] INFO
com.workbrain.util.DataLoader - Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_BREAK.xml]]></message>
<message priority="info"><![CDATA[7610 [main] INFO
com.workbrain.util.DataLoader - Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_PATTERN.xml]]></message>
<message priority="info"><![CDATA[7688 [main] INFO
com.workbrain.util.DataLoader - Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\4-SHIFT_PATTERN_SHIFTS.xml]]></message>
<message priority="info"><![CDATA[8125 [main] INFO
com.workbrain.util.DataLoader - Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
<message priority="info"><![CDATA[Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
 
X

Xicheng Jia

cyberphoo said:
I would like to catch the following pattern:

A substring in the file beginning with the pattern "Importing file" and
ending with the pattern "Modified.*rows in.*table", possibly spanning
multiple lines provided that it contains the string Exception. The
substring should not contain the beginning or ending patterns more than
once...

The following command almost works, except that it may return strings
that contain "Importing file" multiple times:

perl -0777ne "print m!Importing
file[\s\S]*?Exception[\s\S]*?Modified.*table!g;" test.txt

try this one:

perl -ln0777e 'print "Match-",++$n, " ==>\n$1\n\n" while
m{(Importing\sfile(?:(?!Importing\sfile).)*?Exception(?:(?!Importing\sfile).)*?Modified.*?table)}sg'
myfile.txt


perl -ln0777e '
print "Match-",++$n, " ==>\n$1\n\n" while
m{
( # begin of $1
Importing\sfile # header
(?:(?!Importing\sfile).)*? # anything non-header
Exception # at least one
"Exception"
(?:(?!Importing\sfile).)*? # anything non-header
Modified.*?table # ending pattern
) # end of $1
}xsg' myfile.txt

Xicheng
Does anyone know what changes I could make to the regular expression so
that it returns the correct pattern?

Below is a sample document:

<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-AC_VIOLATION.xml]]></message>
<message priority="info"><![CDATA[7047 [main] INFO
com.workbrain.util.DataLoader - Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-DOCKET.xml]]></message>
<message priority="info"><![CDATA[7110 [main] INFO
com.workbrain.util.DataLoader - Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-SHIFT.xml]]></message>
<message priority="info"><![CDATA[7266 [main] INFO
com.workbrain.util.DataLoader - Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-TIME_CODE.xml]]></message>
<message priority="info"><![CDATA[7469 [main] WARN
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement - Commit timeout
or other SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[Commit timeout or other
SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[7469 [main] ERROR
com.workbrain.util.RowPersister - On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[7500 [main] INFO
com.workbrain.util.DataLoader - Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_BREAK.xml]]></message>
<message priority="info"><![CDATA[7610 [main] INFO
com.workbrain.util.DataLoader - Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_PATTERN.xml]]></message>
<message priority="info"><![CDATA[7688 [main] INFO
com.workbrain.util.DataLoader - Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\4-SHIFT_PATTERN_SHIFTS.xml]]></message>
<message priority="info"><![CDATA[8125 [main] INFO
com.workbrain.util.DataLoader - Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
<message priority="info"><![CDATA[Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
 
X

Xicheng Jia

Xicheng said:
cyberphoo said:
I would like to catch the following pattern:

A substring in the file beginning with the pattern "Importing file" and
ending with the pattern "Modified.*rows in.*table", possibly spanning
multiple lines provided that it contains the string Exception. The
substring should not contain the beginning or ending patterns more than
once...

The following command almost works, except that it may return strings
that contain "Importing file" multiple times:

perl -0777ne "print m!Importing
file[\s\S]*?Exception[\s\S]*?Modified.*table!g;" test.txt

try this one:

perl -ln0777e 'print "Match-",++$n, " ==>\n$1\n\n" while
m{(Importing\sfile(?:(?!Importing\sfile).)*?Exception(?:(?!Importing\sfile).)*?Modified.*?table)}sg'
myfile.txt

oops, the indentation is so ugly, and i'd re-arrange it as the
following:

perl -ln0777e '
print "Match-", ++$n, " ==>\n$1\n\n" while
m{
(
# beginning of capturing $1
Importing\sfile
# header pattern
(?:(?!Importing\sfile).)*?
# anything non-header pattern
Exception
# at least one "Exception"
(?:(?!Importing\sfile).)*?
# anything non-header pattern
Modified.*?table
# ending pattern
)
# end of $1
}xsg' myfile.txt

Xicheng
Does anyone know what changes I could make to the regular expression so
that it returns the correct pattern?

Below is a sample document:

<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-AC_VIOLATION.xml]]></message>
<message priority="info"><![CDATA[7047 [main] INFO
com.workbrain.util.DataLoader - Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-DOCKET.xml]]></message>
<message priority="info"><![CDATA[7110 [main] INFO
com.workbrain.util.DataLoader - Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-SHIFT.xml]]></message>
<message priority="info"><![CDATA[7266 [main] INFO
com.workbrain.util.DataLoader - Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-TIME_CODE.xml]]></message>
<message priority="info"><![CDATA[7469 [main] WARN
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement - Commit timeout
or other SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[Commit timeout or other
SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[7469 [main] ERROR
com.workbrain.util.RowPersister - On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[7500 [main] INFO
com.workbrain.util.DataLoader - Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_BREAK.xml]]></message>
<message priority="info"><![CDATA[7610 [main] INFO
com.workbrain.util.DataLoader - Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_PATTERN.xml]]></message>
<message priority="info"><![CDATA[7688 [main] INFO
com.workbrain.util.DataLoader - Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\4-SHIFT_PATTERN_SHIFTS.xml]]></message>
<message priority="info"><![CDATA[8125 [main] INFO
com.workbrain.util.DataLoader - Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
<message priority="info"><![CDATA[Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
 
X

Xicheng Jia

Xicheng said:
Xicheng said:
cyberphoo said:
I would like to catch the following pattern:

A substring in the file beginning with the pattern "Importing file" and
ending with the pattern "Modified.*rows in.*table", possibly spanning
multiple lines provided that it contains the string Exception. The
substring should not contain the beginning or ending patterns more than
once...

The following command almost works, except that it may return strings
that contain "Importing file" multiple times:

perl -0777ne "print m!Importing
file[\s\S]*?Exception[\s\S]*?Modified.*table!g;" test.txt

try this one:

perl -ln0777e 'print "Match-",++$n, " ==>\n$1\n\n" while
m{(Importing\sfile(?:(?!Importing\sfile).)*?Exception(?:(?!Importing\sfile).)*?Modified.*?table)}sg'
myfile.txt

oops, the indentation is so ugly, and i'd re-arrange it as the
following:

Just found a bug, if there is an ending-pattern between the heading
pattern and the first "Exception", so the ending pattern comes before
the first instance of "Exception", then you might get matched with more
than one ending pattern.
so you might add one thing before the "Exception"


perl -ln0777e '
print "Match-", ++$n, " ==>\n$1\n\n" while
m{
(
# beginning of capturing $1
Importing\sfile
# header pattern
(?:(?!Importing\sfile)(?!Modified.*?table).)*?
# anything non-header, non-ending pattern
Exception
# at least one "Exception"
(?:(?!Importing\sfile).)*?
# anything non-header pattern
Modified.*?table
# ending pattern
)
# end of $1
}xsg' myfile.txt

Xicheng
Does anyone know what changes I could make to the regular expression so
that it returns the correct pattern?

Below is a sample document:

<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-AC_VIOLATION.xml]]></message>
<message priority="info"><![CDATA[7047 [main] INFO
com.workbrain.util.DataLoader - Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Modified 21 rows in AC_VIOLATION
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-DOCKET.xml]]></message>
<message priority="info"><![CDATA[7110 [main] INFO
com.workbrain.util.DataLoader - Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Modified 5 rows in DOCKET
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-SHIFT.xml]]></message>
<message priority="info"><![CDATA[7266 [main] INFO
com.workbrain.util.DataLoader - Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Modified 63 rows in SHIFT
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\2-TIME_CODE.xml]]></message>
<message priority="info"><![CDATA[7469 [main] WARN
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement - Commit timeout
or other SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[Commit timeout or other
SQLException.]]></message>
<message priority="info"><![CDATA[java.sql.SQLException: ORA-00001:
unique constraint (WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:2355)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.executeFetch(OCIDBAccess.java:1760)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.oci8.OCIDBAccess.parseExecuteFetch(OCIDBAccess.java:1921)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2864)]]></message>
<message priority="info"><![CDATA[at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.tool.jdbc.proxy.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:179)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.RowPersister.insert(RowPersister.java:398)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importATable(DataLoader.java:474)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importData(DataLoader.java:371)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importAFile(DataLoader.java:309)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.importXml(DataLoader.java:188)]]></message>
<message priority="info"><![CDATA[at
com.workbrain.util.DataLoader.main(DataLoader.java:766)]]></message>
<message priority="info"><![CDATA[7469 [main] ERROR
com.workbrain.util.RowPersister - On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[On inserting into TIME_CODE with ID:
50338 received the error:]]></message>
<message priority="info"><![CDATA[ORA-00001: unique constraint
(WORKBRAIN.UK_TMOD_TCODE_NAME) violated]]></message>
<message priority="info"><![CDATA[while executing INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
Parameters
(50338,FMLA,null,null,YYYYYYY,N,14,0,N,null,null,null,null,null,null,null,null,null,null,9999,null,Y,null,null,Y,N,1,1,N,null,null,null,null,null,null,null,null,null,null,N,null)]]></message>
<message priority="info"><![CDATA[[SQL] INSERT INTO TIME_CODE
(TCODE_ID,TCODE_NAME,TCODE_DESC,TCODE_DEF_HOURS,TCODE_DOW,TCODE_OWS,COLR_ID,HTYPE_ID,TCODE_UNAUTHORIZE,TCODE_FLAG1,TCODE_FLAG2,TCODE_FLAG3,TCODE_FLAG4,TCODE_FLAG5,TCODE_FLAG6,TCODE_FLAG7,TCODE_FLAG8,TCODE_FLAG9,TCODE_FLAG10,TCODE_SORTORDER,TCODE_YAG,TCODE_AFFECTS_BALANCES,TCODE_IRREGULAR,TCODE_DEFAULT_RATE,TCODE_SUMMARIZE,TCODE_ETM_WD_HIDE,LMS_ID,CLIENT_ID,TCODE_IS_LTA,TCODE_UDF1,TCODE_UDF2,TCODE_UDF3,TCODE_UDF4,TCODE_UDF5,TCODE_UDF6,TCODE_UDF7,TCODE_UDF8,TCODE_UDF9,TCODE_UDF10,TCODE_RPT_ISPRDCTV,TCODE_IS_EXCLD_TTL)
VALUES('50338','FMLA',null,null,'YYYYYYY','N','14','0','N',null,null,null,null,null,null,null,null,null,null,'9999',null,'Y',null,null,'Y','N','1','1','N',null,null,null,null,null,null,null,null,null,null,'N',null)]]></message>
<message priority="info"><![CDATA[7500 [main] INFO
com.workbrain.util.DataLoader - Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Modified 36 rows in TIME_CODE
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_BREAK.xml]]></message>
<message priority="info"><![CDATA[7610 [main] INFO
com.workbrain.util.DataLoader - Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Modified 30 rows in SHIFT_BREAK
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\3-SHIFT_PATTERN.xml]]></message>
<message priority="info"><![CDATA[7688 [main] INFO
com.workbrain.util.DataLoader - Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Modified 34 rows in SHIFT_PATTERN
table.]]></message>
<message priority="info"><![CDATA[Importing file:
C:\cruisecontrol-projects\checkout\1-DEVL\Java\..\ApplicationData\QA\StandardData\4-SHIFT_PATTERN_SHIFTS.xml]]></message>
<message priority="info"><![CDATA[8125 [main] INFO
com.workbrain.util.DataLoader - Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
<message priority="info"><![CDATA[Modified 224 rows in
SHIFT_PATTERN_SHIFTS table.]]></message>
 
T

Tad McClellan

Subject: Regular expression help


You should not use regular expressions to process XML data.

I would like to catch the following pattern:

A substring in the file beginning with the pattern "Importing file" and
ending with the pattern "Modified.*rows in.*table", possibly spanning
multiple lines provided that it contains the string Exception. The
substring should not contain the beginning or ending patterns more than
once...


You should use a module that understands XML for processing XML data.


------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;

my @exceptions = parse_exceptions( './test.txt' );
print "$_\n--------------------------\n" for @exceptions;


sub parse_exceptions {
my( $fname ) = @_;
my @messages; # return value

my $ref = XMLin( $fname );
my $str=''; # a buffer
foreach my $msg ( @{ $ref->{message} } ) {

if ( $msg->{content} =~ /Modified.*table/s ) {
$str .= $msg->{content};
push @messages, $str if $str =~ /Exception/;
$str = ''; # empty buffer for next go-round
next;
}

$str .= $msg->{content}; # accumulate to buffer
}

return @messages;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top