Usage of grep command to extract only the words.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Usage of grep command to extract only the words.
# 1  
Old 07-26-2010
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

Code:
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
Code:
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
# 2  
Old 07-26-2010
Code:
$> sed -n 's/.* \(SQLSTATE=[0-9]\+\)/\1/p' infile
SQLSTATE=42603

or
Code:
awk '/SQLSTATE=/ {print $NF}' infile
SQLSTATE=42603

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 07-26-2010
Or with grep:

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

HTH Chris
# 4  
Old 07-26-2010
grep -o not working korn shell

Quote:
Originally Posted by Christoph Spohr
Or with grep:

Code:
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
# 5  
Old 07-26-2010
Code:
# grep "SQLSTATE=*" error.log | sed 's/[^SQLSTATE=[:digit:]]//g'
SQLSTATE=42603

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Question on grep command (extract a string)

Dear all, I have a file a.txt like below: 1_234560_A_G_b37 1 2 1 2 2 2 ... 1_35465767_C_T_b37 2 1 1 2 2 2 ... 2_490638010_A_T_b37 1 2 1 2 2 2 ... 10_4567899_T_G_b37 2 2 1 2 2 2 ... ... what I want to do is extracting rows starting with "10_" like : 10_4567899_T_G_b37 2 2 1 2 2... (1 Reply)
Discussion started by: forevertl
1 Replies

2. Shell Programming and Scripting

Extract words from a pipe

Hello, Currently, I have this output from my application : ------------------------------------------------- Log viewer/Tmp1 (Jun 29 2011 09:48) ------------------------------------------------- BlalbalbaBlalbalba..Blalbalba..Blalbalba..Blalbalba..Blalbalba..Blalbalba..Blalbalba....... (3 Replies)
Discussion started by: acidoangel
3 Replies

3. Shell Programming and Scripting

Need help please with Grep/Sed command to extract text and numbers from a file

Hello All, I need to extract lines from a file that contains ALPHANUMERIC and the length of Alphanumeric is set to 16. I have pasted the sample of the lines from the text file that I have created. My problem is that sometimes 16 appears in other part of the line. I'm only interested to... (14 Replies)
Discussion started by: mnassiri
14 Replies

4. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

5. UNIX for Dummies Questions & Answers

Extract words to new file

Hi there, Unix Gurus Working with big listings of english sentences for my pupils, of the type: 1. If the boss's son had been , someone would have asked for money by now. 2. Look, I haven't a crime, so why can't you let me go? .... I wondered how to extract the words between brackets in... (7 Replies)
Discussion started by: eldeingles
7 Replies

6. Shell Programming and Scripting

expr command to extract words

how to use expr command to retrieve all the words before the equal sign "=" with shell script (3 Replies)
Discussion started by: 76455
3 Replies

7. Shell Programming and Scripting

grep command usage

what is the grep command to get the second occurence of pattern in a file or how to do with sed ? (1 Reply)
Discussion started by: santosh1234
1 Replies

8. Shell Programming and Scripting

Grep command usage in shell

hi, I am facing a problem when i use grep command in shell script. problem is as follows... 1)i has declared an variable (say a) 2)Now i am searching for an pattern in a file and i used the followig command cat /wls_../../scripts/log.txt | grep $a-JUL-08 i am not getting any... (6 Replies)
Discussion started by: hemanth_t
6 Replies

9. Shell Programming and Scripting

How to from grep command from a file which contains matching words?

Hi all I have a file with below content (content is variable whenever new product is launched). I need form a grep command like this egrep "Unknown product|Invalid symboland so on" How to do it using a script? Unknown product Invalid symbol No ILX exch found exceeds maximum size AFX... (4 Replies)
Discussion started by: johnl
4 Replies

10. Shell Programming and Scripting

awk and grep command usage

hi Can anyone explain me how these two commands awk and grep works in a ksh shell Thanks Babu (1 Reply)
Discussion started by: ksmbabu
1 Replies
Login or Register to Ask a Question