| ← Previous | ↑ Home | → Next |
dk-lines [_options_] [_file(s)_]
The program extracts specified lines from a text obtained from the specified files or standard input. It is mainly intended for the Windows platforms, as I do not know about an UTF-16 aware version of "head" or "tail" programs for Windows.
There are 2 processing stages, both stages are optional.
Stage 1: Text at beginning of line.
In the first stage the beginning of each text line is compared against a start text and/or an end text. Lines from within the range (including the borders) are transferred to stage 2. If only start or end text is specified, a simple comparison is used instead of the range check.
Stage 2: Line numbers.
The second stage selects lines from stage 1 output by line numbers. A start line number and/or an end line number can be specified. Positive line numbers are counted from the first line (line number 1) forwards. Negative line numbers are counted from the final line (line number -1) backwards.
| Option | Purpose |
|---|---|
| -f text --from=text |
Start text for stage 1. |
| -t text --to=text |
End text for stage 1. |
| --today | Specify the current date in YYYY-MM-DD notation for start and end text unless specified using -t or -f. You can not use --today if both -t and -f are specified. |
| -l range --lines=range |
Specify the line number range for stage 2. |
| -o --one-stream |
For multiple input files, group the stage 1 results from all files before applying stage 2. Without this option the line number range is applied to each file individually. |
| -i string ‑‑input‑encoding=string |
Expected input encoding, see the Encoding names table below. The encoding specified here is overwritten, if a BOM (byte order marker) is found at start of input. The default is the systems native encoding and endianness. The default is the systems native encoding and endianness. |
| ‑‑line‑size=size | Line buffer size different from the default (4096 bytes). |
| -v --verbose |
Verbose diagnostics. |
| Range specifiction | Example | Selection |
|---|---|---|
| s | Specify start line number s. | |
| 5 | Line 5 and all following lines. | |
| -2 | Final two lines. | |
| s/e | Specify start line number s and end line number e. | |
| 5/10 | Lines 5 to 10. | |
| 5/-2 | Lines from line 5 until (including) penultimate line. | |
| -5/-2 | Range from fifth line from end to penultimate line. | |
| /e | Specify just end line number e. | |
| /5 | Lines from beginning until (including) line 5. | |
| /-2 | Lines from beginning until (including) the penultimate line. |
When producing UTF-16 or 32 bit UNICODE output a BOM is written at start of output. You can suppress the BOM by appending "nobom" to the encoding, i.e. "-o utf-16-le,nobom".
To require a BOM you can append "bom" to the encoding, i.e. "-o utf-8,bom".
0 on success, all other status codes indicate an error.
On Windows the file name length is restricted to _MAX_PATH (260) characters if the file name contains a wildcard (* or ? character).
This program uses DK libraries version 4.
To find files modified in a specified range of dates:
dk-ls -pmn -tf -r | dk-lines --from=2017-11-18 --to=2017-11-19
| Program | Option | Purpose |
|---|---|---|
| dk-ls | List files. | |
| -pmn | Configure output columns:
|
|
| -tf | Restrict output to files (non-directory items). | |
| -r | Recursive listing including all subdirectories. | |
| dk-lines | Extract specific lines from text stream. | |
| --from=2017-11-18 --to=2017-11-19 |
Only those lines beginning with text from (inclusive) "2017-11-18" to (inclusive) "2017-11-19". |
To find files modified today:
dk-ls -pmn -tf -r | dk-lines --today
| Option | Purpose |
|---|---|
| --today | Extract only thos lines beginning with yyyy-mm-dd (current date). |
To find 10 newest files (last modified):
dk-ls -pmn -tf -r | dk-sort | dk-lines -l -10
| Option | Purpose |
|---|---|
| -l -10 | Begin extraction at line 10 before the end. |
To find 10 oldest files (by modification date):
dk-ls -pmn -tf -r | dk-sort | dk-lines -l 1/10
| Option | Purpose |
|---|---|
| -l 1/10 | Extract line number 1 to 10. |
To show file x.txt contents, omit first 3 and final 2 lines:
dk-lines -l 4/-3 x.txt
| Option | Purpose |
|---|---|
| -l 4/-3 | Start at line 4 from the beginning, stop at line 3 before the end. |
| ← Previous | ↑ Home | → Next |