-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!

malik51
  • 23
  • 1
  • 1
  • 6

2 Answers2

4

For that specific data you can:

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

If you might have three colons:

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

You can keep adding more cuts as needed.

The trick is that cut does nothing to a record that doesn't have the delimiter so you can use successive cuts to chop off the first field while leaving the last fields that you've already found alone.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
4

i saw this on another place when I was looking for this answer.

rev, cut (on delimiter) -f 1, rev

move the last field forward, cut it, and move it back

i thought that was kinda slick

yoshi
  • 403
  • 1
  • 6
  • 11