I have a string which looks something like this
dir/subdir/othersubdir/file.txt
But it can also look like
dir/file.txt
or
dir/subdir/file.txt
Now, I am making a script where $P is the full path to the directory were file.txt is.
Now I use this
sed 's/\/.*txt//g'
To be replace anything that ends with txt and comes after a /. This works fine when there is something like dir/file.txt, but not any of my other examples. How can I fix so that it matches what I want?
I don't want to match any subdirectories before .*txt. I want to remove only the file base name.