[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with GREP

Posted on 1998-07-17
4
Medium Priority
?
429 Views
Last Modified: 2010-04-21
I would like to GREP a file, when I find the word I am looking for I would like to retrieve that line and the line above it
i.e. If I was to GREP for TIME, the command would return

Mon Jun 01 15:59:04 1998
This is the TIME

I am using IRIX Unix
0
Comment
Question by:hagenj
[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
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2008858
Depending on your version of grep,
 grep -B1 TIME
may work.  Otherwise, you might try something like
 head -`grep -n TIME file | head -1 | awk -F: '{print $1}'` file | tail -2
0
 
LVL 2

Expert Comment

by:JYoungman
ID: 2008859
grep -B 1 TIME

Does what you are asking for (at least with GNU grep).

0
 
LVL 1

Author Comment

by:hagenj
ID: 2008860
What I am tring to do is search a log file for errors starting with "ORA-", when I find one of this errors I want to read the line above the error because this line contains the time when the error happens. The time command in unix is returning the time the grep command finished, not when the "ORA-" time.
0
 

Accepted Solution

by:
answerman earned 200 total points
ID: 2008861
The "standard" grep cannot do what you want. There is another "version" of grep called cgrep (which I've heard stands for context-grep -- give the context of what you grepped for)

Here's the URL for a perl script that does the same thing

http://www.cs.ruu.nl/pub/PERL/CPAN/scripts/nutshell/ch6/cgrep
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

649 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