3

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?

  • 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
6

Use

echo "${string:index:length}" 

for your example

x="ASDFQWER"
echo "${x:2:3}"
3

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

echo ASDFQWER | cut -c3,4,5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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