Read file from bottom

William Park opengeometry at NOSPAM.yahoo.ca
Tue May 14 15:18:28 EDT 2002


Julia Bell <julia.bell at jpl.nasa.gov> wrote:
>
> > tail | python script.py

> Good idea; I never thought of something like that.
> 
> My initial reaction is that I don't know I exactly how many lines frm the
> bottom I want.  (I currently read the lines, search for data on the lines
> that meets some trigger criterion, and then start processing the data from
> there.)  But, there still might be something worth thinking about regarding
> whether it is more efficient to pre-process the data (similar to using
> 'tail') than to process it as part of my script.

Arrrgh... stop posting at the top.

You can search for that "trigger" and get the line number, ie.
    grep -n '...' file
Then, start printing from that line, ie.
    tail +65 file 

One liner would go something like
    tail +`grep -n '...' file | tail -1 | cut -f 1 -d ':'` | python script.py
    tail +`grep -n '...' file | head -1 | cut -f 1 -d ':'` | python script.py
:-)

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin



More information about the Python-list mailing list