Menu

dk-lines manual

Dirk Krause
← Previous ↑ Home → Next

dk-lines — Select text lines

Synopsis

dk-lines [_options_] [_file(s)_]

Description

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.


Options

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.
Name Encoding
plain Bytes 0x00 to 0xFF represent 32 bit characters U+00000000 to U+000000FF.
win1252 Windows codepage 1252 used by GUI applications on Windows. Formerly named ansi as the Visual Studio documentation names the functions handling such strings as ANSI versions.
utf-8
utf8
UTF-8
utf-16
utf16
UTF-16 in the systems default endianness
utf-16-le
utf-16le
utf16le
utf-16-lsb
&utf-16lsb
utf16lsb
UTF-16 little-endian (least significant byte first)
utf-16-be
utf-16be
utf16be
utf-16-msb
utf-16msb
utf16msb
UTF-16 big-endian (most significant byte first)
c32 32 bit UNICODE in the systems default endianness
c32-le
c32le
c32-lsb
c32lsb
32 bit UNICODE little-endian (least significant byte first)
c32-be
c32be
c32-msb
c32msb
32 bit UNICODE big-endian (most significant byte first)

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


Exit status

0 on success, all other status codes indicate an error.


Restrictions

On Windows the file name length is restricted to _MAX_PATH (260) characters if the file name contains a wildcard (* or ? character).


Notes

This program uses DK libraries version 4.


Examples

Find files modified in a specified range of dates

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:
  • m Modification timestamp
  • n File name
-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".

Find files modified today

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

Find 10 newest files (last modified)

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.

Find 10 oldest files (by modification date)

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.

Show file contents, omit first 3 and final 2 lines

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

Related

Wiki: dk-lines

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.