Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 4
    this is the best answer for command line, I wonder why it isn't more popular Commented Jun 22, 2015 at 23:34
  • 3
    "print NF" print number of words, $NF is the last word.
    – karsten
    Commented Nov 9, 2019 at 15:38
  • No, using shell built-ins is much better when you can avoid an external process. For completeness, perhaps this should show how to use awk -F "x" to use a different separator than space, but again, that's easily done with shell built-ins, too.
    – tripleee
    Commented Apr 16, 2022 at 19:18
  • Simplest is ${A##* }, as in extract=${A##* } or echo ${A##* } edit: as @mwfeamley's answer says.
    – jthill
    Commented Apr 16, 2022 at 19:31