cat command

Hi.
How can i write a command on AIX like the one i did at linux that find string in a file and show me that string, and return 3 lines before and 4 lines after that string.
my linux command is:

/bin/cat     <filename> | tail -150 | grep -B2 -A8 "<string to look for>"

Example:

/bin/cat      /oracle/admin/prd1/bdump/alert_prd1.log | tail -150 | grep -B2 -A8 "ORA-"

i need to do the same on AIX.
I can't find command like this on AIX that can find a string and use parameters to show x lines before that string and x line after that string.
tnx.

Search the forum

GNU grep contains extension to the POSIX version of grep.
Specifically, -B and -A.

Those extensions are not supported on the AIX version of grep, which is
POSIX compliant.

You could use "awk" instead of "grep" and handle the "before" and "after"
lines yourself.

-tony

See also Useless Use of Cat. You can do command < file instead of cat file | command and save on some memory and a lot of time.

Both these assumptions do not stand up to benchmark testing except perhaps on the first use of "cat" after a clean boot.

It's not the same.
I use:

tail -150 /oracle/admin/prd1/bdump/alert_prd1.log | more

and now I can search by

/ORA-/

of course to repeat

/

Don't be ridiculous.

$ time for ((N=0; N<10000; N++)) ; do cat config | grep 32 > /dev/null ; done

real    0m21.712s
user    0m7.800s
sys     0m14.561s
$ time for ((N=0; N<10000; N++)) ; do grep 32 < config > /dev/null ; done

real    0m14.115s
user    0m5.932s
sys     0m9.381s
$

...and this is on a dual-core system. If grep had to time-share with cat, the performance would be worse yet. There is of course a cost in resources and time to launching a process and piping data through it, especially for small amounts of data. It's only insignificant when you do it once.

Keeping on topic for a minute... AIX grep doesn't have such "extensions" (and for TRB, most grep's I would imagine, are POSIX compliant, but AIX has extensions of its own (like -p, which make dealing with it's heavily-stanza-based system files easier)).

anbu23 had the correct answer - this question has been asked many times. Search the forums.

Gentlemen,
First, if a read from disk once it was already in the cache disk, for the next reading was not reading from the disk.
Second, the time for entering commands from the keyboard to be unreasonably long, in scripts, in cron, it's OK.
In interactive mode I include the filename after command tail without a cat.

---------- Post updated at 08:30 PM ---------- Previous update was at 08:06 PM ----------

corona688:
It's formum AIX not intel8080 or z80 now 15 september 2010.

The principle is architecture-independent, and the cost remains large in the fastest machines -- extra process creation, double the reads and writes, much more I/O involving the kernel, many more context switches, and having to wait for it when its dead. If anything it's more important not to waste time and memory in large-scale machines expected to perform consistently under very high loads. You're wasting a core that'd otherwise be doing real work.

Hi,
Let's come back time when not allowed to start X, for a very charged the processor. Only character mode. I can laugh, I remember those time.
If you're teacher, you're right, young computer scientists should think, it's good trening.
Bye