If sam wants to extract the column of the name and its contents from the following data, which command should he use? Name:StudentNo:Hobby LiZeYin:12304:football YangBo:12305:basketball ZhangQian:12306:football a. cut -d ":" -f1 b. cut -d ":" -c1-5 c. sort -d ":" -f1 d. sort -d ":" -c1-5
时间: 2024-02-15 21:04:32 浏览: 73
面向对象程序设计:JavaSE-任务11
The correct answer is:
a. cut -d ":" -f1
Explanation:
The `cut` command is used to extract specific columns or fields from a file. The `-d` option specifies the delimiter (in this case, the colon), and the `-f` option specifies the field or column number to extract.
To extract the first column (which contains the names), Sam should use the following command:
```
cut -d ":" -f1
```
This will output:
```
Name
LiZeYin
YangBo
ZhangQian
```
Option b (`cut -d ":" -c1-5`) would extract the first five characters of each line, which is not what Sam wants. Option c (`sort -d ":" -f1`) would sort the file by the first field, but would not extract it. Option d (`sort -d ":" -c1-5`) is not a valid command, as the `-c` option is not supported by `sort`.
阅读全文