el – extract lines from text files


el (from extract lines) is a unix tool to efficiently extract lines from a text file using a dynamic line end index. Its command line syntax is tuned to work with other posix tools – especially grep – to easily operate on poor man's databases where each of the database's columns is in a separate newline separated file.

Since el mmaps the whole file, it does not work on streams.

Build instructions

Get the source from my git repository git clone git://erdgeist.org/el and type make in the directory el. el has no further dependencies and can just be copied to /usr/local/bin or wherever your binaries reside.


In its simplest form just run:

echo 1 2 3 4 5 6 7 8 9 10 | el file.txt

to extract lines 1 to 10 from the file file.txt and print them to stdout. el also accepts white space separated line numbers with the -i parameter and can default to hexadecimal numbers with the -x switch:

el -i "10 11 12 13" -x file1.txt file2.txt

extracts line 16 to 19 from the files file.txt and file2.txt, each line separated by the tab character. If your line numbers start at 0, el will add 1, if it is run with the -0 switch.

The reason reading line numbers from stdin and not from command line by default becomes apparent, when you use the combining features of el, as it can parse and generate output as the grep posix tool does.

If you use the -n switch, each extracted line is prefixed by it's line number and a colon, just as grep does. If you use the -g switch, el will also expect the line numbers on stdin to be terminated by a colon followed by garbage until next newline. So you can feed results from grep -n directly to it. With the -G option, not only will el parse the line numbers from grep's output, but also append the extracted lines from each file to the input line. In order to chain several grep and el commands, best combine the -Gn switches as in this example:

grep -n Manager positions.txt | el -Gn firstname.txt lastname.txt | grep Jon | el -Gn salary.txt

This will produce, an output like this:


given that all the text files contain corresponding rows of information about the staff.


el was written by Dirk Engling, who likes to hear from happy customers.


el is considered beer ware.