diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-11-07 22:13:40 +0100 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-11-07 22:13:40 +0100 |
commit | d0fa8ffb43684853b626595abd3d650e86ef4d63 (patch) | |
tree | aad827697bf9318c826c1105d79feffbca4757df /src/cli/cut.md | |
parent | 1070b7b60308925b9c0f98075c354bb05b6f25ca (diff) | |
download | notes-d0fa8ffb43684853b626595abd3d650e86ef4d63.tar.gz notes-d0fa8ffb43684853b626595abd3d650e86ef4d63.zip |
cli: add cut and rev, update tac
Diffstat (limited to 'src/cli/cut.md')
-rw-r--r-- | src/cli/cut.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cli/cut.md b/src/cli/cut.md new file mode 100644 index 0000000..aa7f7f0 --- /dev/null +++ b/src/cli/cut.md @@ -0,0 +1,41 @@ +# cut(1) + +```sh +# Remove sections from each line of files(s). +cut OPT FILE [FILE] + -d DELIM delimiter to tokenize + -f LIST field selector + -c LIST character selector +``` + +## Example: only selected characters + +```sh +echo 'aa bb cc dd' | cut -c "1-4" +# aa b + +# Inverted selection. +echo 'aa bb cc dd' | cut --complement -c "1-4" +# b cc dd +``` + +## Example: only selected fields +Fields in `cut` are indexed starting from `1` rather than `0`. +```sh +# Fields 2 until 3. +echo 'aa bb cc dd' | cut -d ' ' -f 2-3 +# bb cc + +# First field until the 2nd. +echo 'aa bb cc dd' | cut -d ' ' -f -2 +# aa bb + +# Third field until the end. +echo 'aa bb cc dd' | cut -d ' ' -f 3- +# cc dd + +# If the number of tokens in a line is unkown but we want to remove the last 2 +# tokens we can use rev(1). +echo 'aa bb cc dd' | rev | cut -d ' ' -f3- | rev +# aa bb +``` |