Solved

UNIX Shell cut, grep, sed

Posted on 2011-09-30
7
463 Views
Last Modified: 2012-05-12
I have a line on field 6 that contains two Oracle errors.  I'd like to only cut the words "ORA-01653" and "ORA-12096"  How do I achieve it? (the Oracle errors can be different each time the job runs)  The line is pipe delimited.

Shedule Job,Daily Schedule Job|Data Load-IL|28-SEP-10|28-SEP-10|Failed|ORA-12096: error in view log on T_RATE_PLAN" ORA-01653: unable to extend table MLOG$_T_RATE_PLAN by 1024 in tablespace SYSTEM|
0
Comment
Question by:scpig
7 Comments
 
LVL 9

Expert Comment

by:user_n
ID: 36894230
regular expression

    A way of specifying and matching strings for shells (filename wildcarding), grep (file searches), sed, and awk.

http://compute.cnr.berkeley.edu/cgi-bin/man-cgi?regex+5
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 36894500
Hi scpig, by cutting I understand that you want to filter out the ORA messages. I'm assuming that your lines are in a file called test.txt

This is what you will do the trick::

cut -d"|" -f6 test.txt | grep -o "ORA-[0-9]*"

Open in new window


First part will cut out field #6 with | as a field separator in your file test.txt. Second part will grep for the ORA error numbers and print them each on a new line.

The command above on your line above will produce this output:
ORA-12096
ORA-01653

Open in new window

0
 

Author Comment

by:scpig
ID: 36894668
When I tried it, it gave me this error:
cut -d"|" -f6 test.txt | grep -o "ORA-[0-9]*"

grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .

My machine is Linux.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Expert Comment

by:Tintin
ID: 36894877
What Linux distro are you running?

It's very unusual that it would come with GNU grep.
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 250 total points
ID: 36895715
@Tintin - I'm using FC15 - GNU grep 2.8

You may try this awk version if you like:

cut -d"|" -f6 test.txt | awk -- '{for (i=1; i<=NF; i++) if ($i ~ /ORA-[0-9]*/) print $i}'

Open in new window

0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 36896285
:) Saw in the result that there is a trailing colon (:) - this one has filtered that:

cut -d"|" -f6 test.txt | awk -- '{for (i=1; i<=NF; i++) if ($i ~ /ORA-[0-9]*/) { sub(/:$/,"",$i) ; print $i } }'

Open in new window

0
 

Author Closing Comment

by:scpig
ID: 36903753
This works well on my machine.  Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Glyph icons in Bootstrap 3 4 37
[HTML] Graphic not centered on page 4 44
WordPress Themes 10 34
Bad <form> statement? 9 20
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now