Solved

UNIX Shell cut, grep, sed

Posted on 2011-09-30
7
461 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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 …

747 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

9 Experts available now in Live!

Get 1:1 Help Now