Implements a missing feature of the "cut" common tools linux/unix command which is: -d accepts a string not just a single character.
The tool also accepts multiple -f options.
Just as simple as that.
SCut means Superb Cut because it's superb.
Version: v1.0
- Program will fail if you ask for a fragment (-f) too high and finds a row that does not have that many fragments. I am considering a --skip-invalid-rows or something.
- I wanted to learn GO, this is my second program implemented right after Hello World so please forgive me for stupid mistakes but please free to give me suggestions :)
- I could not believe that cut still did not accept multiple characters for the -d parameter.
Keep in mind: if you provide a filename, it must be the last parameter!
scut -d ";;;" -f 1 FILENAME
cat long_file.txt | scut -d ";;;" -f 1
scut -d ";;;" -f 1 -f 3 FILENAME
scut -d ";;;" -f 1 -f 3 -cs "," FILENAME
In special cases this can be used to change a sequence of characters (-d) to another sequence of characters (-cs).
I cross compiled without testing to the following operating systems and architectures:
- Windows 32/amd64/arm64
- Linux 32/amd64/arm64
- Macos amd64/arm64
go install github.com/hacker-szabo/scut@latest
I used go 1.21 but it might work for way lower versions as well.
- Download the source code (or at least scut.go)
- Navigate to the directory in the terminal/command line
go build scut.go
With go installed you can cross compiled by following the basic GO cross compile way:
Find your target operating system (GOOS) and architecture (GOARCH) in the following table:
| aix | ppc64 | | android | 386 | | android | amd64 | | android | arm | | android | arm64 | | darwin | amd64 | | darwin | arm64 | | dragonfly | amd64 | | freebsd | 386 | | freebsd | amd64 | | freebsd | arm | | illumos | amd64 | | ios | arm64 | | js | wasm | | linux | 386 | | linux | amd64 | | linux | arm | | linux | arm64 | | linux | loong64 | | linux | mips | | linux | mipsle | | linux | mips64 | | linux | mips64le | | linux | ppc64 | | linux | ppc64le | | linux | riscv64 | | linux | s390x | | netbsd | 386 | | netbsd | amd64 | | netbsd | arm | | openbsd | 386 | | openbsd | amd64 | | openbsd | arm | | openbsd | arm64 | | plan9 | 386 | | plan9 | amd64 | | plan9 | arm | | solaris | amd64 | | wasip1 | wasm | | windows | 386 | | windows | amd64 | | windows | arm | | windows | arm64 |
Table copied from: https://go.dev/doc/install/source#environment
scut -d Delimiter_string -f fragment1 [-f fragment2] [-cs colum_separator] [file]
Delimiter string; the string provided with the -d option is the Delimiter where the rows will be cut; the default delimiter is a tab character ("\t"). Space and other characters with special meanings within the context of the shell in use must be enquoted or escaped as necessary.
The fragment number (starts with 1, not 0) to print each line. The same as -f in the original cut command but you can add multiple of them and they will be printed all with a TAB character in between.
Column separator. By default TAB. This character (or string ;)) will appear in the output between multiple columns if and only you provided multiple fragments.
The file (and accompanying path if necessary) to process as input. If no file is specified then standard input will be used.
TODO