user613114 user613114 - 1 year ago 159
Linux Question

Unix cut except last two tokens

I'm trying to parse file names in specific directory. Filenames are of format:


I need to cut the tokens using delimiter
, and need to take string except the last two tokens. In above examlpe output should be

The number of tokens is not fixed. I've tried to do it with
option of
command, but did not find any solution. Any ideas?

Answer Source

With cut:

$ echo | rev | cut -d_ -f3- | rev

The 3- in -f3- means "from N’th field, to end of line"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download