← 返回命令列表

Linux command

choose 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Select first field

echo "one two three" | choose 0

Select third field

echo "a b c d e" | choose 2

Select range of fields

echo "a b c d e" | choose 1:3

Select from end (last field)

echo "a b c d e" | choose -1

Select last three fields

echo "a b c d e" | choose -3:

Custom field separator

echo "a,b,c" | choose -f ',' 1

Regex field separator

echo "a1b2c" | choose -f '[0-9]' 0:

Select exclusive range

echo "a b c d e" | choose 1:4 --exclusive

说明

choose is a human-friendly, fast alternative to cut and awk for selecting fields from text input. It uses Python-like slice syntax with zero-based indexing, negative indices for counting from the end, and inclusive ranges by default. Unlike cut, which requires exact delimiter specification and uses 1-based indexing, choose handles whitespace splitting automatically and supports regex-based field separators. Written in Rust, it is significantly faster than awk for simple field selection tasks.

参数

-f, --field-separator _sep_
Field separator (regex supported)
-o, --output-field-separator _sep_
Output separator (default: space)
-x, --exclusive
Exclude end index from range
-c, --character-wise
Select characters instead of fields
-n, --non-greedy
Use non-greedy field splitting

FAQ

What is the choose command used for?

choose is a human-friendly, fast alternative to cut and awk for selecting fields from text input. It uses Python-like slice syntax with zero-based indexing, negative indices for counting from the end, and inclusive ranges by default. Unlike cut, which requires exact delimiter specification and uses 1-based indexing, choose handles whitespace splitting automatically and supports regex-based field separators. Written in Rust, it is significantly faster than awk for simple field selection tasks.

How do I run a basic choose example?

Run `echo "one two three" | choose 0` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f, --field-separator _sep_ do in choose?

Field separator (regex supported)