Cut using delimiter that has multiple chars including special chars

Hi Team,

I have a file data as follows.

FROM XYZ.[dbo].[STG_PRQ_UVW] ]]><ReadStatementFromFile type='bool'><![CDATA[0]]></ReadStatementFromFile><Tables collapsed='1'></Tables><Parameters collapsed='1'></Parameters><Columns collapsed='1'></Columns></SelectStatement><EnablePartitioning collapsed='1' type='bool'><![CDATA[0]]></EnablePartitioning></SQL><Transaction><RecordCount modified='1' type='int'><![CDATA[20000]]></RecordCount><EndOfWave collapsed='1' type='int'><![CDATA[0]]></EndOfWave></Transaction><Session><IsolationLevel type='int'><![CDATA[1]]></IsolationLevel><AutocommitMode type='int'><![CDATA[0]]></AutocommitMode><ArraySize modified='1' type='int'><![CDATA[20000]]></ArraySize><SchemaReconciliation><FailOnSizeMismatch type='bool'><![CDATA[1]]></FailOnSizeMismatch><FailOnTypeMismatch type='bool'><![CDATA[1]]></FailOnTypeMismatch><FailOnCodePageMismatch type='bool'><![CDATA[0]]></FailOnCodePageMismatch></SchemaReconciliation><PassLobLocator collapsed='1' type='bool'><![CDATA[0]]></PassLobLocator><CodePage collapsed='1' type='int'><![CDATA[0]]></CodePage></Session><BeforeAfter collapsed='1' type='bool'><![CDATA[0]]></BeforeAfter><LimitRows collapsed='1' type='bool'><![CDATA[0]]></LimitRows></Usage></Properties >

I have a requirement to search for the text “]]><ReadStatementFromFile” and print the text before the delimiter. The expected output should be as follows.

FROM XYZ.[dbo].[STG_PRQ_UVW]

The linux version that I am working on is 3.10

Can anyone please help me out with the command?

Thanks
Krishna.

Try awk:

awk -F ']]><ReadStatementFromFile' '{ print $1}'  input_file
out=$(awk -F ']]><ReadStatementFromFile' '{ print $1}'  input_file)
echo "$out"

The -F set a new fs for the input field separator and $1 print first value and $2 prints ]]><ReadStatementFromFile

Thank you Sir. It worked.