bash - Remove part of the path in shell -


echo "/dir1/dir2/filename.txt" | sed ???? 

what should sed expression output

   /dir1/filename.txt 

if there other simpler way achieve this, welcome.

you can cut:

$ echo "/dir1/dir2/filename.txt" | cut -d/ -f1,2,4 /dir1/filename.txt 

with sed little mess:

$ echo "/dir1/dir2/filename.txt" | sed 's/^\(\/.*\)\(\/.*\)\(\/.*\)/\1\3/' /dir1/filename.txt 

the idea portions of /text \(\/.*\) , print ones want, 1 , 3, \1\3.


Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -