19

How to cut till first delimiter / and get remaining part of strings?

Ex:

pandi/sha/Dev/bin/boot

I want to cut pandi, so the output like

sha/Dev/bin/boot
  • What should be the output for an input like /full/path or //host/path or dir/ or file-path-with-no-slash? – Stéphane Chazelas Sep 26 '17 at 9:50
  • 1
    You didn't mention what tool you wanted to use for cutting. And there is no "till" in your source string to cut, so your question is confusing. Did you mean "'til", "until", or "up to", instead? – Suncat2000 Sep 26 '17 at 14:23
40

Simply with cut command:

echo "pandi/sha/Dev/bin/boot" | cut -d'/' -f2-
sha/Dev/bin/boot

  • -d'/' - field delimiter

  • -f2- - a range of fields to output (-f<from>-<to> ; in our case: from 2 to the last)

21

Using shell (POSIX sh/bash/Korn/zsh) parameter substitution expansion.

string="pandi/sha/Dev/bin/boot"
echo "${string#*/}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.