Geek Lair

Archive for December 2009

Extracting a substring from a starting point using awk

leave a comment »

If you have a string like this (this is how versions look in Clearcase):


and want to extract the string 78 (i.e, the version no.), you can do it this way:

echo "/root_path/stream/version_name/78" | awk '{where = match($0,"\/[^\/]*$"); print substr($0,where+1)}'

We get the position of the last occurrence of “/” and use substr to extract the string after that position till end of string.

Written by anonir

December 29, 2009 at 19:07

Posted in Linux

Tagged with