哪些Linux shell命令返回一个字符串的一部分? [英] What linux shell command returns a part of a string?
本文介绍了哪些Linux shell命令返回一个字符串的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找到一个Linux命令,可以返回一个字符串的一部分。在大多数编程语言,它的 SUBSTR()
功能。确实的bash具有可以用于此目的的任何命令。我希望能够做这样的事情... SUBSTRABCDEFG2 3
- 版画 CDE
I want to find a linux command that can return a part of the string. In most programming languages, it's the substr()
function. Does bash have any command that can be used for this purpose. I want to be able to do something like this...
substr "abcdefg" 2 3
- prints cde
.
随后类似的问题:
- Extract substring in bash
推荐答案
如果你正在寻找一个shell工具做这样的事情,你可以使用剪切
命令
If you are looking for a shell utility to do something like that, you can use the cut
command.
要采取你的榜样,请尝试:
To take your example, try:
echo "abcdefg" | cut -c3-5
这将产生
cde
其中, -CN-M
告诉削减命令列 N
返回中号
,包容性的。
Where -cN-M
tells the cut command to return columns N
to M
, inclusive.
这篇关于哪些Linux shell命令返回一个字符串的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文