Concatenate file(s) to standard output or file https://github.com/ethauvin/dcat
Find a file
2023-12-15 13:16:21 -08:00
.github/workflows Updated GitHub and GitLab workflows 2023-12-15 13:03:30 -08:00
.idea Support for Dart 3.2.3 2023-12-15 12:49:58 -08:00
bin Support for Dart 3.2.3 2023-12-15 12:49:58 -08:00
example Added example. 2021-10-20 22:43:05 -07:00
lib Code cleanup. 2022-01-30 09:21:41 -08:00
test Code cleanup. 2022-01-30 09:21:41 -08:00
.codecov.yml Turned off Codecov patch analysis. 2021-10-16 15:28:47 -07:00
.gitignore Initial release cleanup. 2022-01-26 16:39:22 -08:00
.gitlab-ci.yml Updated GitHub and GitLab workflows 2023-12-15 13:03:30 -08:00
.pubignore Version 1.0.0 2022-01-27 15:58:21 -08:00
analysis_options.yaml Initial commit. 2021-10-09 17:18:56 -07:00
analyze.sh Fixes suggested by pub.dev. 2022-01-28 13:07:34 -08:00
CHANGELOG.md Version 1.0.1 2022-01-30 09:22:12 -08:00
compile.sh Added compile script. 2021-10-16 00:46:47 -07:00
coverage.sh Support for Dart 3.2.3 2023-12-15 12:49:58 -08:00
dcat.iml Initial commit. 2021-10-09 17:18:56 -07:00
docs.sh Support for Dart 3.2.3 2023-12-15 12:49:58 -08:00
format.sh Fixes suggested by pub.dev. 2022-01-28 13:07:34 -08:00
LICENSE Updated copyright. 2022-01-26 15:32:36 -08:00
pubspec.lock Updated dependencies 2023-12-15 13:16:21 -08:00
pubspec.yaml Updated dependencies 2023-12-15 13:16:21 -08:00
README.md Support for Dart 3.2.3 2023-12-15 12:49:58 -08:00
test.sh Code cleanup. 2022-01-30 09:21:41 -08:00

License (3-Clause BSD) GitHub CI codecov pub package

dcat: Concatenate File(s) to Standard Output or File

A Dart command-line and library implementation of the standard cat Unix utility, inspired by the Write command-line apps sample code.

Synopsis

dcat sequentially reads files, or standard input if none are given, writing them to standard output or file.

Command-Line Usage

dcat --help
Usage: dcat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

  -A, --show-all                 equivalent to -vET
  -b, --number-nonblank          number nonempty output lines, overrides -n
  -e, --show-nonprinting-ends    equivalent to -vE
  -E, --show-ends                display $ at end of each line
  -h, --help                     display this help and exit
  -n, --number                   number all output lines
  -t, --show-nonprinting-tabs    equivalent to -vT
  -T, --show-tabs                display TAB characters as ^I
  -s, --squeeze-blank            suppress repeated empty output lines
  -v, --show-nonprinting         use ^ and M- notation, except for LFD and TAB
      --version                  output version information and exit

Examples:
  dcat f - g  Output f's contents, then standard input, then g's contents.
  dcat        Copy standard input to standard output.

Compile Standalone Application

Linux / MacOS

dart compile exe -o bin/dcat bin/dcat.dart

Windows

dart compile exe bin/dcat.dart

Library Usage

dart pub add dcat
import 'package:dcat/dcat.dart';

final result = await cat(['path/to/file', 'path/to/otherfile]'],
    File('path/to/outfile').openWrite());
if (result.isFailure) {
  for (final error in result.errors) {
    print('Error: ${error.message}');
  }
}

View Full Instructions

The cat function supports the following parameters:

Parameter Description Type
paths The file paths. String[]
output The standard output or file. IOSink
input The standard input. Stream
showEnds Same as -e bool
numberNonBlank Same as -b bool
showLineNumbers Same as -n bool
showTabs Same as -T bool
squeezeBlank Same as -s bool
showNonPrinting Same as -v bool
  • paths and output are required.
  • output should be an IOSink such as stdout or a File stream.
  • input can be stdin.

The remaining optional parameters are similar to the GNU cat utility.

A CatResult object is returned which contains the exitCode (exitSuccess or exitFailure) and errors, if any:

final result = 
    await cat(['path/to/file'], stdout, showLineNumbers: true);
if (result.exitCode == exitSuccess) { // or result.isSuccess
  // ...
} else {
  for (final error in result.errors) {
    stderr.writeln("Error with '${error.path}': ${error.message}");
  }
}

View Full Example