mirror of
https://github.com/uutils/sed.git
synced 2026-06-10 16:14:15 -07:00
856d2bbd25cc34ba29898c5a3cc5080a21a327f7
fails with running rustup to ensure you have aarch64-pc-windows-msvc installed info: component 'rust-std' for target 'aarch64-pc-windows-msvc' is up to date building aarch64-pc-windows-msvc target, from x86_64-unknown-linux-gnu host, via cargo-xwin, using cargo profile dist --workspace) ⏬ Downloading MSVC CRT... ✅ Downloaded MSVC CRT in 1m 13s. error: rustc 1.87.0 is not supported by the following packages: sed@0.1.1 requires rustc 1.88 sed@0.1.1 requires rustc 1.88 sed@0.1.1 requires rustc 1.88 sed@0.1.1 requires rustc 1.88 sysinfo@0.37.2 requires rustc 1.88 × failed to find bin sed.exe for path+file:///__w/sed/sed#0.1.1 help: did the above build fail?
sed
Rust reimplementation of the sed utility with some GNU sed, FreeBSD sed, and other extensions.
Status
At this state sed implements all POSIX commands and can run correctly the two complex scripts of its integration tests: hanoi.sed (solves the Towers of Hanoi puzzle) and 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.
Further work aims to:
- Adjust buffering on terminal output to match current implementations,
- Implement more GNU extensions,
- Improve performance where possible.
Installation
Ensure you have Rust installed on your system. You can install Rust through rustup.
Clone the repository and build the project using Cargo:
git clone https://github.com/uutils/sed.git
cd sed
cargo build --release
cargo run --release
The binary is named sed in target/release/sed.
Extensions and incompatibilities
Supported GNU extensions
- Command-line arguments can be specified in long (
--) form. - Spaces can precede a regular expression modifier.
Ican be used in as a synonym for thei(case insensitive) substitution flag.- In addition to
\n, other escape sequences (octal, hex, C) are supported in the strings of theycommand. Under POSIX these yield undefined behavior. - The
a,c, andicommands 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
\0is a synonym for &. - A
Qcommand (optionally followed by an exit code) quits immediately. - The
qcommand can be optionally followed by an exit code. - The
lcommand can be optionally followed by the output width. - The
--follow-symlinksflag for in-place editing.
Supported BSD and GNU extensions
- The second address in a range can be specified as a relative address with +N.
- In-place editing of file with the
-iflag.
New extensions
- Unicode characters can be specified in regular expression pattern, replacement
and transliteration sequences using
\uXXXXor\UXXXXXXXXsequences. - The
lcommand lists Unicode characters using the\uXXXXand\UXXXXXXXXsequences.
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.
- 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 the last file. If files specified in subsequent arguments until the last one are empty, then the last line condition will never be triggered. This behavior is consistent with the original implementation. - Labels are parsed for alphanumeric characters. The BSD version parses them until the end of the line, preventing ; to be used as a separator.
License
sed is licensed under the MIT License - see the LICENSE file for details
Languages
Rust
90.8%
Shell
5.4%
Python
3.8%