can i get a substring from a string?

for example, the string a is "abcdefg", can i get a substring "bcd" (from a[1]to a[3]) from string a?

thank you

Not very pretty, but you could do:

echo $string | sed 's/^.//;s/...$//'

You could also do this:

echo $string | cut -c2-4

:slight_smile:

thanks

Well this thread certainly has me confused. :confused:

The question is in a c programming forum and the phrasing of the question would seem to indicate a c question. Yet some shell based answers seemed to satisfy the OP. Just in case this is a c question, I like to add:

for(i=0,j=1; j<=3; i++,j++)
     b=a[j];
b=0;