summaryrefslogtreecommitdiff
path: root/stories/projects/el.rst
blob: 86331819ff1e8d490b1dcba3e5acca1dc626d200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
.. link:
.. description: is a unix tool aiding the Telefonbuch project for export and search queries.
.. tags: project
.. date: 2015/02/01 19:10:08
.. title: el
.. subtitle: extract lines from text files
.. slug: ../arts/software/el/index
.. prio: 100

.. contents::
  :depth: 1
  :class: ezjail-toc

----

Overview
========

*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.

----

Invocation
==========

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::

  17:Manager\tJon\tMiller\t$1200
  23:Manager\tJon\tDoe\t$1600

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

----

Author
======

*el* was written by `Dirk Engling <mailto:erdgeist@erdgeist.org>`_, who likes to hear from happy customers.

----

License
=======

*el* is considered `beer ware </beerware.html>`_.