https://github.com/riquito/tuc Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Skills + GitHub Sponsors + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} riquito / tuc Public * Notifications * Fork 3 * Star 249 When cut doesn't cut it License GPL-3.0 license 249 stars 3 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights riquito/tuc This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 10 tags Code Latest commit @riquito riquito Set correct version of rustc required ... 5ed0c81 Jun 13, 2022 Set correct version of rustc required 5ed0c81 Git stats * 226 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Rebase onto master Jun 11, 2022 doc Fix the command name in the manpage. Jun 13, 2022 src Allow no right bounds in fwd only --lines algorithm Jun 13, 2022 tests Transform -e from a flag to an option Jun 13, 2022 .gitignore Initial import May 24, 2020 CHANGELOG.md Update CHANGELOG Jun 13, 2022 Cargo.lock Bump version to 0.10.0 Jun 13, 2022 Cargo.toml Bump version to 0.10.0 Jun 13, 2022 LICENSE Add license May 30, 2020 README.md Set correct version of rustc required Jun 13, 2022 View code tuc (when cut doesn't cut it) Install Help Examples LICENSE README.md tuc (when cut doesn't cut it) version ci license You want to cut on more than just a character, perhaps using negative indexes or format the selected fields as you want... Maybe you want to cut on lines (ever needed to drop first and last line?)... That's where tuc can help. Install Download one of the prebuilt binaries or run # requires rustc >= 1.61.0 cargo install tuc # append `--features regex` if you want regex support Help tuc 0.11.0 [UNRELEASED] Cut text (or bytes) where a delimiter matches, then keep the desired parts. The data is read from standard input. USAGE: tuc [FLAGS] [OPTIONS] FLAGS: -g, --greedy-delimiter Match consecutive delimiters as if it was one -p, --compress-delimiter Print only the first delimiter of a sequence -s, --only-delimited Print only lines containing the delimiter -V, --version Print version information -z, --zero-terminated Line delimiter is NUL (\0), not LF (\n) -h, --help Print this help and exit -m, --complement Invert fields (e.g. '2' becomes '1,3:') -j, --(no-)join Print selected parts with delimiter inbetween OPTIONS: -f, --fields Fields to keep, 1-indexed, comma separated. Use colon to include everything in a range. Fields can be negative (-1 is the last field). [default 1:] e.g. cutting on '-' the string 'a-b-c-d' 1 => a 1: => a-b-c-d 1:3 => a-b-c 3,2 => cb 3,1:2 => ca-b -3:-2 => b-c To re-apply the delimiter add -j, to replace it add -r (followed by the new delimiter). You can also format the output using {} syntax e.g. '["{1}", "{2}"]' => ["a", "b"] You can escape { and } using {{ and }}. -b, --bytes Same as --fields, but it keeps bytes -c, --characters Same as --fields, but it keeps characters -l, --lines Same as --fields, but it keeps lines Implies --join. To merge lines, use --no-join -d, --delimiter Delimiter used by --fields to cut the text [default: \t] -e, --regex Use a regular expression as delimiter -r, --replace-delimiter Replace the delimiter with the provided text -t, --trim Trim the delimiter (greedy). Valid values are (l|L)eft, (r|R)ight, (b|B)oth Options precedence: --trim and --compress-delimiter are applied before --fields or similar Memory consumption: --characters and --fields read and allocate memory one line at a time --lines allocate memory one line at a time as long as the requested fields are ordered and non-negative (e.g. -l 1,3:4,4,7), otherwise it allocates the whole input in memory (it also happens when -p or -m are being used) --bytes allocate the whole input in memory Examples # Cut and rearrange fields... echo "foo bar baz" | tuc -d ' ' -f 3,2,1 bazbarfoo # ...and apply back the delimiter... echo "foo bar baz" | tuc -j -d ' ' -f 3,2,1 baz bar foo # ...or replace it echo "foo bar baz" | tuc -j -r ' ' -d ' ' -f 3,2,1 baz bar foo # Keep ranges echo "foo bar baz" | tuc -d ' ' -f 2: bar baz # Cut using a greedy delimiter echo "foo bar" | tuc -g -d ' ' -f 1,2 foobar # Format output echo "foo bar baz" | tuc -d ' ' -f '{1}, {2} and lastly {3}' foo, bar and lastly baz # Support \n echo "100Kb README.txt 2049-02-01" | tuc -d ' ' -f '{2}\n+-- {1}\n+-- {3}' README.txt +-- 100Kb +-- 2049-02-01 # Cut lines (e.g. drop first and last line) printf "a\nb\nc\nd\ne" | tuc -l 2:-2 b c d # Concatenate lines printf "a\nb\nc\nd\ne" | tuc -l 1,2 --no-join ab # Compress delimiters after cut echo "foo bar baz" | tuc -d ' ' -f 2: -p bar baz # Replace remaining delimiters with something else echo "foo bar baz" | tuc -d ' ' -f 2: -p -r ' -> ' bar -> baz # Indexes can be negative and rearranged echo "a b c" | tuc -d ' ' -f -1,-2,-3 cba # Cut using regular expressions (requires a release with regex features enabled) echo "a,b, c" | tuc -e '[, ]+' -f 1,3 ac # Delimiters can be any number of characters long echo "abc" | tuc -d '' -f 1,3 ac # Cut characters (expects UTF-8 input) echo "" | tuc -c 4,3,2,1 # Cut bytes (the following emoji are 4 bytes each) echo "" | tuc -b 5:8 # Keep non-matching fields echo "a b c" | tuc --complement -d ' ' -f 2 ac LICENSE Tuc is distributed under the GNU GPL license (version 3 or any later version). See LICENSE file for details. About When cut doesn't cut it Resources Readme License GPL-3.0 license Stars 249 stars Watchers 2 watching Forks 3 forks Releases 10 v0.10.0 Latest Jun 13, 2022 + 9 releases Packages 0 No packages published Contributors 4 * @riquito riquito Riccardo Attilio Galli * @dependabot[bot] dependabot[bot] * @bjorn3 bjorn3 * @LawnGnome LawnGnome Adam Harvey Languages * Rust 100.0% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.