Разрежь ложь, если делимер не существует

360
nullUser

Например:

$ cut -d ' ' -f 2- <<< "example" example 

Почему резать мне врут, говоря мне, что «пример» - это второй разделитель и так далее. Я хочу его напечатать, ""так как нет второго разделителя.

Обратите внимание, что это правильно:

$ cut -d ' ' -f 2- <<< "example " 
1

1 ответ на вопрос

1
John1024

You need to use the -s option:

$ cut -d ' ' -sf 2- <<< "example" $ 

By default, if a line has no delimiters, cut will print the entire line. -s turns this behavior off.

Not that your second example, does have a delimiter:

cut -d ' ' -f 2- <<< "example " 

Because the line has a delimiter, cut does what you expect.

Documentation

This behavior is documented in man cut:

-f, --fields=LIST
select only these fields; also print any line that contains no delimiter character, unless the -s option is specified

Похожие вопросы