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

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -