Take the 2-minute tour ×
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:

input:

    ASDFQWER

output:

    DFQ

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
add comment

2 Answers 2

up vote 5 down vote accepted

Use

echo "${string:index:length}" 

for your example

x="ASDFQWER"
echo "${x:2:3}"
share|improve this answer
add comment

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

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

Your Answer

 
discard

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.