Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

UNIX Shell cut, grep, sed

Posted on 2011-09-30
7
Medium Priority
?
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1000 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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

688 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