Remove path prefix from unix tree

Viewed 9957

I have a requirements in UNIX command where i have a path similar to this:

path/to/file/manyfiles.extensions

now i want the output something similar to-

file/manyfiles.extensions

now i can do this listing both /path/to and /path removing them one by one.

but i might get only "/path/to" as my input and i have to remove both from the tree in one command.

You might think that i can list 2 folders to remove, but in many a cases i get structures having 12-13 of subfolders in which i need only the first and last folder in many cases.

eg - `Source files - target/classes/

Remove prefix - target`

Result:

classes/my/code/HelloWorld.class
classes/my/code/HelloWorldImpl.class
classes/my/code/Main.class
3 Answers
Related