20

This code will give the first part, but how can I remove it and get the whole string without the first part?

echo "first second third etc"|cut -d " " -f1
4

5 に答える 5

38

を参照してください。意味info cutが説明されていf1ます。

実際には、2 番目のフィールドの後にフィールドが必要です。-fはフィールドで検索するようコマンドに指示し2-、2 番目以降のフィールドを意味します。

echo "first second third etc" | cut -d " " -f2-
于 2012-12-09T14:15:34.170 に答える
17

You can use substring removal for that. There isn't any need for external tools:

$ foo="a b c d"
$ echo "${foo#* }"
b c d
于 2012-12-09T14:17:08.203 に答える
7

できるよ:

echo "first second third etc" | cut -d " " -f2-
>> second third etc
于 2012-12-09T14:15:36.937 に答える
3

これを試してください:

echo "first second third etc" | cut -d " " -f2-

で説明されています

 man cut | less +/N-

N- N 番目のバイト、文字、またはフィールドから行末まで

Bash tagがある限り、次のようにBash パラメータ展開を使用できます。

x="first second third etc"
echo ${x#* }
于 2012-12-09T14:15:43.233 に答える
1

これを試して:

  echo "first second third etc" | cut -d " " -f2-
于 2012-12-09T14:16:49.133 に答える