I have a path in linux bash script in a variable. This path could be
/a/b/c/d/t.json
/a/b/c/d/e/f/t.json
/a/b/t.json
I want to get the first 2 directories. The output should be /a/b
for all 3 example paths above.
try:
echo "$pathvar" | cut -d/ -f 1-3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With