Binny V A Binny V A - 1 year ago 103
Linux Question

What linux shell command returns a part of a string?

I want to find a linux command that can return a part of the string. In most programming languages, it's the

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

Subsequent similar question:

Answer Source

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

which yields


Where -cN-M tells the cut command to return columns N to M, inclusive.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download