Usage of grep command to extract only the words.

Dear Folks,
I am a newbee to UNIX. I want to extract the SQLSTATE from a log file. For example the log file content is

SQL0010N  The string constant beginning with "' from   table1 a, table 2" does not have
an ending string delimiter.  SQLSTATE=42603

when I give the the command as

grep "SQLSTATE" error.log

I am getting the output as "an ending string delimiter. SQLSTATE=42603"

But my requirement is to get the output as "SQLSTATE=42603". Please help me with proper grep command. Thanks in advance

$> sed -n 's/.* \(SQLSTATE=[0-9]\+\)/\1/p' infile
SQLSTATE=42603

or

awk '/SQLSTATE=/ {print $NF}' infile
SQLSTATE=42603
1 Like

Or with grep:

grep -o "SQLSTATE=[0-9][0-9]*" error.log

HTH Chris

chris..Thanks for your reply.grep -o is NOT recognized by my shell. I am using Korn Shell

# grep "SQLSTATE=*" error.log | sed 's/[^SQLSTATE=[:digit:]]//g'
SQLSTATE=42603