AWK / SED skript

Environment: SUN, tcsh
As a newbie in Unix scripts...
I need a script to take a file as a parameter (or piped into it)
and do the following:

1. search for a specific string
  (ie. "ORA-")
2. The search is for 2 or 3 diferent
   strings
3. The string case to search is upper
   and lower case.
4. If any of the search strings were
    found: output the line containing
    the string and the 3 lines before
    that string.

*** I managed to do all but number 4
    with:
    cat file_name |send -n -e '/ORA-/p'

Thanks
Alon
alonpAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
den_tsopaConnect With a Mentor Commented:
well, there is another way:
cat file_name | perl -e 'while (<>) { push(@a,$_); shift @a if ($#a>3); print "--\n".join("",@a) if (/(ORA\-)|(ANOTHER)/); }'

it is not SED or AWK and now it will be comment (not answer) ;)
0
 
den_tsopaCommented:
cat file_name | grep -B 3 -i 'ORA-'

what you mean "the search is for 2 or 3 diferent strings"?
if you need to search not only 'ORA-' words, e.g. ANOTHER word, try:

cat file_name | egrep -B 3 -i -e '(ORA\-)|(ANOTHER)'
0
 
chris_calabreseCommented:
Pleas comment on why den_tsopa's answer is wrong.  It looks like it should work to me.
0
 
urimCommented:
This is comment on behalf Alonp,
Den_tsopa, the -B flag doesn't exists in SUN environment (at least not in 2.6)
0
All Courses

From novice to tech pro — start learning today.