Concatenate file(s) to standard output or file
https://github.com/ethauvin/dcat
.github/workflows | ||
.idea | ||
bin | ||
doc/api | ||
lib | ||
test | ||
.gitignore | ||
analysis_options.yaml | ||
CHANGELOG.md | ||
compile.sh | ||
coverage.sh | ||
dcat.iml | ||
LICENSE | ||
pubspec.lock | ||
pubspec.yaml | ||
README.md |
dcat: Concatenate File(s) to Standard Output or File
A cat command-line and library implementation in Dart, inspired by the Write command-line apps sample code.
Synopsis
dcat copies each file, or standard input if none are given, 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
--version output version information and exit
-v, --show-nonprinting use ^ and U+ notation, except for LFD and TAB
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
*nix
dart compile exe -o bin/dcat bin/dcat.dart
Windows
dart compile exe bin/dcat.dart
Library Usage
import 'package:dcat/dcat.dart';
final result = await cat(['path/to/file', 'path/to/otherfile]'], File('path/to/outfile'));
if (result.exitCode == exitFailure) {
for (final message in result.messages) {
print("Error: $message");
}
}
The cat
function supports the following parameters:
Parameter | Description | Type |
---|---|---|
paths | The file paths. | String[] |
output | The standard output or file. | IOSink or File |
input | The standard input. | Stream<List<int>>? |
log | The log for debugging. | List<String>? |
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
andoutput
are required.output
should be anIOSink
likestdout
or aFile
.input
can bestdin
.log
is used for debugging/testing purposes.
The remaining optional parameters are similar to the GNU cat utility.
A CatResult
object is returned which contains the exitCode
(exitSuccess
or exitFailure
) and error messages
if any:
final result = await cat(['path/to/file'], stdout);
if (result.exitCode == exitSuccess) {
...
}
Differences from GNU cat
- No binary file support.
- A line is considered terminated by either a
CR
(carriage return), aLF
(line feed), aCR+LF
sequence (DOS line ending). - A line ending is automatically appended to the last line of any read file.
- The
U+
notation is used instead ofM-
for non-printing characters.