且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在txt文件的每一行中打印第一个单词unix bash

更新时间:2023-09-01 19:59:28

要打印整个单词,您需要-f 1,而不是-c 1.而且由于默认的字段定界符是TAB而不是SPACE,因此您需要使用-d选项.

To print a whole word, you want -f 1, not -c 1. And since the default field delimiter is TAB rather than SPACE, you need to use the -d option.

cut -d' ' -f1 filename

要打印使用cut的AFAIK不可能完成的最后两个单词,因为它只能从行的开头开始计数.使用awk代替:

To print the last two words not possible with cut, AFAIK, because it can only count from the beginning of the line. Use awk instead:

awk '{print $(NF-1), $NF;}' filename