Reading from text

Grant Edwards invalid at invalid
Tue Feb 17 19:12:34 CET 2009

On 2009-02-17, oamram <oamram at> wrote:

> i have a directory with about 50 text file and i need to
> iterate through them and get line 7 to 11 from each file and
> write those lines into another file(one file that will contain
> all lines).

Assuming this is a real task and not a homework problem, then
I'd do it this way:

  $ cd [directory containing 50 test files]
  $ (for file in *; do head -n11 $file | tail -n5; done) >/path/to/results-file.txt

Grant Edwards                   grante             Yow! ... My pants just went
                                  at               on a wild rampage through a
                                 Long Island Bowling Alley!!

More information about the Python-list mailing list