用 cut 或 awk 剪切輸入?

用 cut 或 awk 剪切輸入?

我基本上是嘗試使用 bash 腳本解析原始 IRC 輸入,並且我想獲取訊息,而不是其他任何東西。我想要保存的一個例子是

:[email protected] PRIVMSG #channel :this is the message

所以,我認為這樣就可以了,我可以用「剪切」來挑戰。我繼續使用cut -d ':' -f3,但很快發現,如果用戶發布了帶有「:」的內容,它會破壞「解析」。

答案1

您可以指定一個範圍字段。要從欄位 3 到達結尾:cut -d: -f3-

$ line=':[email protected] PRIVMSG #channel :this is the message: all of it'
$ echo "$line" | cut -d: -f3
this is the message
$ echo "$line" | cut -d: -f3-
this is the message: all of it

相關內容