Operating System - HP-UX
1748051 Members
5021 Online
108757 Solutions
New Discussion юеВ

Re: how to extract from a file

 
SOLVED
Go to solution
Carlos Fernandez Riera
Honored Contributor

Re: how to extract from a file

Hi Procura:


I think Perl i will like Perl too much, it is a very human readable :-)))
unsupported
H.Merijn Brand (procura
Honored Contributor

Re: how to extract from a file

Well, it *is* readable if you use long variable names and formatting, but this is a one-liner. If the original autor (or anyone else) would like an explanation, I could create it as a file with formatting, indents and comments to make the onscure become obvious.
Enjoy, Have FUN! H.Merijn
Trond Haugen
Honored Contributor

Re: how to extract from a file

It's not neat and it don't do anny error checking but it works:

FILE=MyLargeFile
lastSTRING=$( grep -n STRING $FILE | tail -1 | cut -f1 -d:)
from=$(expr $lastSTRING + 5)

tail -$from $FILE | head -19


Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Trond Haugen
Honored Contributor

Re: how to extract from a file

Sorry, I was too quick with my answer. It should read:

FILE=MyLargeFile
linesinfile$( wc -l $FILE) lastSTRING=$( grep -n STRING $FILE | tail -1 | cut -f1 -d:)
from=$(expr $lastSTRING + 6)
TAIL=$(expr $linesinfile - $from)
tail -$from $FILE | head -19


Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Trond Haugen
Honored Contributor

Re: how to extract from a file

Do I get anything right today!?
Missing linefeed. This should be right:
FILE=MyLargeFile
linesinfile$( wc -l $FILE)
lastSTRING=$( grep -n STRING $FILE | tail -1 | cut -f1 -d:)
from=$(expr $lastSTRING + 6)
TAIL=$(expr $linesinfile - $from)
tail -$from $FILE | head -19

Regards,
Trond
Regards,
Trond Haugen
LinkedIn