如何切到第一个定界符并获得字符串的剩余部分?


24

如何切到第一个定界符/并获得字符串的剩余部分?

例如:

pandi/sha/Dev/bin/boot

我想剪切pandi,所以输出像

sha/Dev/bin/boot

/full/path//host/pathdir/或或输入的输出应该是什么file-path-with-no-slash
斯特凡Chazelas

1
您没有提到要使用哪种工具进行切割。而且您的源字符串中没有要剪切的“耕种”,因此您的问题令人困惑。您是说“直到”,“直到”还是“最多”?
Suncat2000

Answers:


48

只需使用cut命令:

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

  • -d'/' -字段分隔符

  • -f2--要输出的字段范围(-f<from>-<to>在我们的示例中:从2到最后)


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.