string search

Hi,

There is a very big flat file called Protokoll.txt
keep on appending more and more records
wc -l also will take lot of time, it is production data.

from this file I want to list out the line containing
last occurence of the string "ServedParty=123".

if I give like this :

$grep "ServedParty=123" Protokoll.txt
What I want is Last line of the above result.

It will take lot of time, because it will search from
top, but I need to search from bottom.

Kindly mail me to :

::email removed::

Why don't you give a try to 'tail' command. It will read your file from the bottom. Then you can use pipes to find the appropriate strings/.
Good luck

If it's that large, to where wc takes a long time, perhaps it's time to either split the file up, or impliment some database system.

The only thing I can think of is to use tac to pipe it through grep, and possibly the results of THAT through head.

Also, lest we not forget our Unix toolboxes, Perl may be able to do that. I'm not very proficient with Perl yet, so I can't help more there...

If what you are looking for is at the end of your file try:
<pre>

tail |grep ServedParty

</pre>

Cheers

:0)

You might want to copy all or part of the file to a temporary file name. This won't speed it up but it will help prevent from corrupting the log file that is being appended.

cp protokoll.txt /tmp/protokoll.txt
grep string /tmp/protokoll.txt

If you want to break down the file into smaller sections to search use the split command. Do an man on split to see how it works.

Then cp that output to the /tmp directory and grep away!

:smiley: :cool: