-1

Let's say I've the following data:

ae722d1d94dcd3b161af166936:!]z@.:123
09338b2b29919e6c0daefbcce0361335:21f2e48d86f28ab7cd5c9c95:123
$H$92Gh.gRJwECLPzkjACPihoLg/:123
c6f1cb5f1feeece60f9a8e067e0:v4Zz'Cj5_Ze{J+iRW{2z,<~:123
202cb962a75b964b07152d234b70:123
40bd0015630c35165329ea5ecbdbbeef:123

(Invaild hashes, for explaining purpose only)

I want to use the cut tool in printing the last field only.

123
123
123
123
123
123
  • I don't want to use rev command.
  • I want nothing other than cut, I know how to do it in sed, awk.

--complement flag might help!

4

2 回答 2

4

当我在寻找这个答案时,我在另一个地方看到了这个。

rev, cut (在分隔符上) -f 1, rev

将最后一个字段向前移动,剪切,然后向后移动

我觉得那有点滑

于 2013-06-17T15:50:45.680 回答
4

对于该特定数据,您可以:

cut -f2- -d: file | cut -f2 -d:

如果你可能有三个冒号:

cut -f2- -d: file | cut -f2- -d: | cut -f2 -d:

您可以根据需要继续添加更多cuts。

诀窍是对cut没有分隔符的记录没有任何作用,因此您可以使用连续cut的 s 来切断第一个字段,同时保留您已经找到的最后一个字段。

于 2012-05-26T03:27:17.113 回答