-3

I have this file path called :

images/Linux/RHEL7-x64/PTSVPL/ptsvpl-esxi-x86_64-7.20.0302.vmdk

and i want to extract the string from the end from this i.e i want the string : ptsvpl-esxi-x86_64-7.20.0302.vmdk from whole line, please help me for the same.

every time the path vairies and sub folders extends so taught to fetch only the string from last and which has '/' in it after my intented string

vinay
  • 53
  • 1
  • 8

2 Answers2

2

There is a command for this:

% file tail images/Linux/RHEL7-x64/PTSVPL/ptsvpl-esxi-x86_64-7.20.0302.vmdk
ptsvpl-esxi-x86_64-7.20.0302.vmdk

Documentation: file

Peter Lewerin
  • 13,140
  • 1
  • 24
  • 27
0

Try:

[^\/]*$

This will match all characters except slashes coming after a slash or the beginning of your string in case there are no slashes.

Good Night Nerd Pride
  • 8,245
  • 4
  • 49
  • 65
  • 1
    Actually, `[^/]*$` is sufficient: you don't need a capture group. – Peter Lewerin Nov 06 '16 at 15:04
  • The slash isn't a special character in Tcl REs, so you don't need to escape it. And even if it were, it wouldn't be special inside a bracket expression. – Peter Lewerin Nov 06 '16 at 15:11
  • thanks that regexp worked [^/]*$ and with this i got the output as : ptsvpl-esxi-x86_64-7.20.0302.vmdk next is can i get any regexp which will filter only 7.20.0302 from the whole string? basically extract ptsvpl-esxi-x86_64-{7.20.0302}.vmdk which is flower bracketted and get that as output – vinay Nov 06 '16 at 15:32
  • @vinay: try `lindex [split [file rootname [file tail $path]] -] end` with your path stored in the variable `$path`. – Peter Lewerin Nov 06 '16 at 17:00