I executed a following sed command
=> echo "a/b/c/d/e/f/g/h" | sed 's/\/[A-Za-z0-9]*$//g'
a/b/c/d/e/f/g
Now what if I want to extract "g" from "a/b/c/d/e/f/g/h" . That is second last string using SED.
I executed a following sed command
=> echo "a/b/c/d/e/f/g/h" | sed 's/\/[A-Za-z0-9]*$//g'
a/b/c/d/e/f/g
Now what if I want to extract "g" from "a/b/c/d/e/f/g/h" . That is second last string using SED.
Try...
basename $(dirname "a/b/c/d/e/f/g/h")
How will we do using SED?
Try this:
$ echo "a/b/c/d/e/f/g/h" | sed 's!.*/\(.*\)/.*!\1!'
g
$
Hi Shell_Learner,
In awk it's bit simple as follows:
echo "a/b/c/d/e/f/g/h" |awk -F"/" '{ print $(NF-1) }'
might be needed for you in future