Help me please: UNIX command to extract substring not squeeze spaces

view story

http://www.unix.com – Hi experts, Please help me!... I have a string " test1 test2 test3 ". There are two spaces before "test1"; There are four spaces between "test1" and "test2"; there are two spaces between "test2 and "test3". I want to extract a substring "2 test3" using positions. Below is my test script: Code: ************ str=" test1 test2 test3 " start_pos=16 val_end_pos=23 temp_val=`echo $str | cut -c$start_pos-$val_end_pos` echo $temp_val ************ The result is "t3". It seems the multiple spaces are sque (HowTos)