https://github.com/ethauvin/dcat
Concatenate file(s) to standard output.
https://github.com/ethauvin/dcat
android cat concat concatenate dart flutter ios linux macos windows
Last synced: 3 months ago
JSON representation
Concatenate file(s) to standard output.
- Host: GitHub
- URL: https://github.com/ethauvin/dcat
- Owner: ethauvin
- License: bsd-3-clause
- Created: 2021-10-10T00:08:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T21:16:29.000Z (about 2 years ago)
- Last Synced: 2025-07-20T17:46:29.437Z (6 months ago)
- Topics: android, cat, concat, concatenate, dart, flutter, ios, linux, macos, windows
- Language: Dart
- Homepage:
- Size: 144 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/licenses/BSD-3-Clause)
[](https://github.com/ethauvin/dcat/actions/workflows/dart.yml)
[](https://codecov.io/gh/ethauvin/dcat)
[](https://pub.dev/packages/dcat)
# dcat: Concatenate File(s) to Standard Output or File
A [Dart](https://dart.dev/) command-line and library implementation of the standard **cat** Unix utility, inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline).
## Synopsis
**dcat** sequentially reads files, or standard input if none are given, writing them to standard output or file.
## Command-Line Usage
```console
dcat --help
```
```text
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
```console
dart compile exe -o bin/dcat bin/dcat.dart
```
### Windows
```console
dart compile exe bin/dcat.dart
```
## Library Usage
```console
dart pub add dcat
```
```dart
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](https://pub.dev/packages/dcat/install)
The `cat` function supports the following parameters:
Parameter | Description | Type
:--------------- |:----------------------------- | :-------------------
paths | The file paths. | String[]
output | The standard output or file. | [IOSink](https://api.dart.dev/dart-io/IOSink-class.html)
input | The standard input. | [Stream](https://api.dart.dev/dart-io/Stdin-class.html)
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](https://api.dart.dev/dart-io/IOSink-class.html) such as `stdout` or a [File](https://api.dart.dev/dart-io/File/openWrite.html) stream.
* `input` can be [stdin](https://api.dart.dev/dart-io/Stdin-class.html).
The remaining optional parameters are similar to the [GNU cat](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation) utility.
A `CatResult` object is returned which contains the `exitCode` (`exitSuccess` or `exitFailure`) and `errors`, if any:
```dart
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](https://github.com/ethauvin/dcat/blob/master/example/example.dart)