Files
sed/README.md
T

129 lines
5.2 KiB
Markdown
Raw Permalink Normal View History

2025-02-01 18:07:27 +01:00
[![Crates.io](https://img.shields.io/crates/v/sed.svg)](https://crates.io/crates/sed)
[![Discord](https://img.shields.io/badge/discord-join-7289DA.svg?logo=discord&longCache=true&style=flat)](https://discord.gg/wQVJbvJ)
[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/uutils/sed/blob/main/LICENSE)
[![dependency status](https://deps.rs/repo/github/uutils/sed/status.svg)](https://deps.rs/repo/github/uutils/sed)
[![CodeCov](https://codecov.io/gh/uutils/sed/branch/master/graph/badge.svg)](https://codecov.io/gh/uutils/sed)
# sed
Rust reimplementation of the [sed utility](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/sed.html)
2025-04-22 15:44:09 +03:00
with some [GNU sed](https://www.gnu.org/software/sed/manual/sed.html),
[FreeBSD sed](https://man.freebsd.org/cgi/man.cgi?sed(1)),
and other extensions.
2025-02-01 18:07:27 +01:00
2025-05-10 08:49:18 +02:00
## Status
2025-06-04 11:30:54 +03:00
At this state _sed_ implements all POSIX commands
2025-08-08 15:57:44 +03:00
and can run correctly the two complex scripts of its integration tests:
2025-06-04 11:30:54 +03:00
[hanoi.sed](https://github.com/uutils/sed/blob/main/tests/fixtures/sed/script/hanoi.sed) (solves the Towers of Hanoi puzzle) and
[math.sed](https://github.com/uutils/sed/blob/main/tests/fixtures/sed/script/math.sed) (implements an arbitrary precision integer math calculator).
The performance of this Rust implementation is now better than the GNU and FreeBSD implementations for most benchmarked cases.
2025-11-23 22:39:44 +01:00
Further work aims to:
* Adjust buffering on terminal output to match current implementations,
* Implement more GNU extensions,
* Improve performance where possible.
2025-05-10 08:49:18 +02:00
2025-02-01 18:07:27 +01:00
## Installation
Ensure you have Rust installed on your system. You can install Rust through [rustup](https://rustup.rs/).
Clone the repository and build the project using Cargo:
```bash
git clone https://github.com/uutils/sed.git
cd sed
cargo build --release
cargo run --release
```
2025-11-23 22:43:46 +01:00
2025-12-14 11:04:39 +01:00
The binary is named `sed` in `target/release/sed`.
2025-11-23 22:43:46 +01:00
2025-12-21 13:05:37 +01:00
## Testing
### GNU sed Compatibility Testing
Test compatibility against GNU sed using the comprehensive testsuite (47+ tests, ~10% pass rate):
```bash
# Clone GNU sed testsuite (one time setup)
git clone https://github.com/mirror/sed.git ../gnu.sed
# Run compatibility tests
./util/run-gnu-testsuite.sh
# Generate JSON results for CI
./util/run-gnu-testsuite.sh --json-output results.json
```
The testsuite extracts test cases from the GNU sed repository and tests them against expected outputs.
### Unit Tests
```bash
cargo test
```
## Extensions and incompatibilities
2025-05-18 15:36:35 +02:00
### Supported GNU extensions
2025-04-22 15:44:09 +03:00
* Command-line arguments can be specified in long (`--`) form.
2025-04-27 15:16:30 +03:00
* Spaces can precede a regular expression modifier.
2025-05-10 13:53:37 +03:00
* `I` can be used in as a synonym for the `i` (case insensitive) substitution
flag.
2025-05-13 20:24:56 +03:00
* In addition to `\n`, other escape sequences (octal, hex, C) are supported
in the strings of the `y` command.
Under POSIX these yield undefined behavior.
2025-07-27 09:37:25 +03:00
* The `a`, `c`, and `i` commands do not require an initial backslash,
allow text to appear on the same line, and support escape sequences
in the specified text.
* The substitution command replacement group `\0` is a synonym for &.
* A `Q` command (optionally followed by an exit code) quits immediately.
* The `q` command can be optionally followed by an exit code.
* The `l` command can be optionally followed by the output width.
2025-05-30 18:21:30 +03:00
* The `--follow-symlinks` flag for in-place editing.
2026-01-20 13:42:08 +02:00
* Address 0 can be used to specify an address range that is already
active on line 1 and can finish with the specified regular expression.
2026-01-23 12:22:58 +02:00
* Address steps can be specified in the form of start~step and start,~step
ranges.
2025-04-27 15:16:30 +03:00
2025-05-09 17:52:03 +03:00
### Supported BSD and GNU extensions
* The second address in a range can be specified as a relative address with +N.
2025-05-30 18:21:30 +03:00
* In-place editing of file with the `-i` flag.
2025-05-09 17:52:03 +03:00
### New extensions
* Unicode characters can be specified in regular expression pattern, replacement
and transliteration sequences using `\uXXXX` or `\UXXXXXXXX` sequences.
* The `l` command lists Unicode characters using the `\uXXXX` and `\UXXXXXXXX`
sequences.
2025-05-09 17:52:03 +03:00
### Incompatibilities
* The input is assumed to be valid UTF-8 (this includes 7-bit ASCII).
If the input is in another code page, consider converting it through UTF-8
in order to avoid errors on invalid UTF-8 sequences and for the correct
handling of regular expressions.
This _sed_ program can also handle arbitrary byte sequences if no part of the
input is treated as string.
2025-05-17 17:29:53 +03:00
* The command will report an error and fail if duplicate labels are found
in the script.
This matches the BSD behavior. The GNU version accepts duplicate labels.
* The last line (`$`) address is interpreted as the last non-empty line of
2025-05-09 17:52:03 +03:00
the last file. If files specified in subsequent arguments until the last
one are empty, then the last line condition will never be triggered.
2025-05-10 14:01:31 +03:00
This behavior is consistent with the
[original implementation](https://github.com/dspinellis/unix-history-repo/blob/Research-V7/usr/src/cmd/sed/sed1.c#L665).
* Labels are parsed for alphanumeric characters. The BSD version parses them
until the end of the line, preventing ; to be used as a separator.
2025-02-01 18:07:27 +01:00
2026-01-11 21:12:00 +01:00
## GNU test suite compatibility
Below is the evolution of how many GNU tests uutils passes.
![Evolution over time](https://github.com/uutils/sed-tracking/blob/main/gnu-results.svg?raw=true)
2025-02-01 18:07:27 +01:00
## License
sed is licensed under the MIT License - see the `LICENSE` file for details