octosquidopus
octosquidopus

Reputation: 3713

How to display only the last field?

I used

cut -d " " -f 8

and

awk '{print $8}'

But this assumes that the 8th field is the last one, which is not always true.

How can I display the last field in a shell script?

Upvotes: 0

Views: 5018

Answers (2)

Jonathan Wakely
Jonathan Wakely

Reputation: 171263

Edit: this answer is wrong now because the question changed. Move along, nothing to see here.

You can use tail to print a specified number of bytes from the end of the input

tail -c 1

Upvotes: 2

Gilles Quénot
Gilles Quénot

Reputation: 185015

Try doing this :

$ awk '{print $NF}'

or the funny

$ echo "foo bar base" | rev | cut -d ' ' -f1 | rev
base

Upvotes: 4

Related Questions