Uses awk
to provide cut
like syntax for field extraction. The command name is rcut
.
⚠️ ⚠️ Work under construction!
cut
's syntax is handy for many field extraction problems. But it doesn't allow multi-character or regexp delimiters. So, this project aims to provide cut
like syntax for those cases. Currently uses mawk
in a bash
script.
ℹ️ Note that rcut
isn't feature compatible or a replacement for the cut
command. rcut
helps when you need features like regexp field separator.
awk
-d
) and output (-o
) field separators can be multiple charactersmawk
by defaultgawk
for better regexp support with -g
option-F
option
-o
is not used, value passed to the -d
option will be set as the output field separator-
separator (same as cut
)
-
by itself means all the fields (this is also the default if -f
option isn't used at all)1
-n
option
-1
means the last field, -2
means the second-last field and so on:
to specify field ranges,
character (same as cut
)cut
, order matters with the -f
option and field/range duplication is also allowed
-c
(complement) is not active-c
option will print all the fields in the same order as input except the fields specified by -f
option-s
option will suppress lines not matching the input field separator1
⚠️ ⚠️ Work under construction!
$ cat spaces.txt 1 2 3 x y z i j k # by default, it uses awk's space/tab field separation and trimming # unlike cut, order matters $ rcut -f3,1 spaces.txt 3 1 z x k i # multi-character delimiter $ echo 'apple:-:fig:-:guava' | rcut -d:-: -f2 fig # regexp delimiter $ echo 'Sample123string42with777numbers' | rcut -d'[0-9]+' -f1,4 Sample numbers # fixed string delimiter $ echo '123)(%)*#^&(*@#.[](\\){1}\xyz' | rcut -Fd')(%)*#^&(*@#.[](\\){1}\' -f1,2 -o, 123,xyz # multiple ranges can be specified, order matters $ printf '1 2 3 4 5\na b c d e\n' | rcut -f2-3,5,1,2-4 2 3 5 1 2 3 4 b c e a b c d # last field $ printf 'apple ball cat\n1 2 3 4 5' | rcut -nf-1 cat 5 # except last two fields $ printf 'apple ball cat\n1 2 3 4 5' | rcut -cnf-2: apple 1 2 3 # suppress lines without input field delimiter $ printf '1,2,3,4\nhello\na,b,c\n' | rcut -sd, -f2 2 b # -g option will switch to gawk $ echo '1aa2aa3' | rcut -gd'a{2}' -f2 2
See Examples.md for many more examples.
You can use script.awk to check if all the example code snippets are working as expected.
$ cd examples/ $ awk -f script.awk Examples.md
1
for field rangecut
that can use a regex delimiter, works on compressed files, etcecho 'bGVhcm5ieWV4YW1wbGUubmV0QGdtYWlsLmNvbQo=' | base64 --decode
or send a DM via twitterThis project is licensed under MIT, see LICENSE file for details.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4