Hi,
I have a input file with following contents
---------------------------------------------------------Run Number: 1-----------------------------------------------------------
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Started|05/28/2007 02:19:30|TEST|8651
---------------------------------------------------------out_file-----------------------------------------------------------
item_id|status_desc|description
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Completed|05/28/2007 02:19:33|TEST|8651
---------------------------------------------------------Run Number: 2-----------------------------------------------------------
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Started|05/28/2007 02:27:25|TEST|24745
---------------------------------------------------------out_file-----------------------------------------------------------
item_id|status_desc|description
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Completed|05/28/2007 02:27:27|TEST|24745
---------------------------------------------------------Run Number: 3-----------------------------------------------------------
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Started|05/28/2007 02:56:32|TEST|5560
---------------------------------------------------------out_file-----------------------------------------------------------
item_id|status_desc|description
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Completed|05/28/2007 02:56:34|TEST|5560
---------------------------------------------------------Run Number: 4-----------------------------------------------------------
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Started|05/28/2007 02:57:32|TEST|11961
---------------------------------------------------------out_file-----------------------------------------------------------
item_id|status_desc|description
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Completed|05/28/2007 02:57:33|TEST|11961
---------------------------------------------------------Run Number: 5-----------------------------------------------------------
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Started|05/28/2007 04:17:31|TEST|24685
---------------------------------------------------------out_file-----------------------------------------------------------
item_id|status_desc|description
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]|Completed|05/28/2007 04:17:33|TEST|24685
Input to the script will be
test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]
My job is to extract the last occurance of the expression that is from IP_EXPR|Started tp IP_EXPR|Completed
I tried with
sed but it gives the following error
sed: -e expression #1, char 40: extra characters after command
Following is my code
IP="test_run -layout test_vaal -i [ /x/TEST/batch/temp/20070528_ip.txt /x/TEST/batch/temp/20070528__op.txt]"
IP_FILE="test.txt"
EXPR=`echo $IP |
sed 's/\[//g' |
sed 's/\]//g'`
echo "EXPR is : ${EXPR}"
EXTRACTED=`cat $IP_FILE |
sed 's/\[//g' |
sed 's/\]//g' |
sed 's/ /!/g' |
sed -n "/${EXPR}/,/${EXPR}/p" `
echo "EXTRACTED is : ${EXTRACTED}"
Can somebody help me out in this
Raghu