man grep, since you have not (or Im half blind today...) said what OS.
For instance, in HP-UX 11 and previous you have no option -w.
to have something alike you can do:
The problem appears to be that $DB_TRANS is an environment variable not a pointer to the name of a file. If this is the case the line break between messages is lost and you just have one long string.
Needs a re-think about where to store the error messages so that they can be processed line-by-line with "egrep".
DB_TRANS=$(sqlplus $USERID/$PASSWORD@$DATABASE << EOF
set head off
set feed off
set serveroutput on
CREATE TABLE TBL1(
OLD_ID VARCHAR2(6) PRIMARY KEY,
NEW_ID VARCHAR2(6),
DATE DATE
);
commit;
/
EOF)
Sorry, but DB_TRANS is an environment variable. This is the problem. You cannot store multiple lines in an environment variable for your purpose because the line breaks get lost. The whole contents of ${DB_TRANS} is one concatonated line.
Try redirecting the output to a file not to an environment variable. You can then use "egrep" on the file as described in many earlier posts.
Using single pattern search I am able to get each error on seperate line. So asked the same. Why it is not working for multiple pattern search in grep command.