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.