Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

How can I crop unneeded chars, and only output what I need? For example:





I mean in this case I need only the 3.-4.-5. chars of the string. How do I do that?

share|improve this question
It may help future readers if you could edit/clarify your question to state whether you are working with shell variables or text I/O streams. Given the answer you chose to accept, it seems you were looking for the former but that is not entirely clear from the question. – jw013 Dec 26 '11 at 17:52

2 Answers 2

up vote 6 down vote accepted


echo "${string:index:length}" 

for your example

echo "${x:2:3}"
share|improve this answer

cut is the simplest program I know which is able to do that. example:

echo ASDFQWER | cut -c3,4,5
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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