Sorting a string

Hello all, I have some 20-digit strings - say 1234567890abcdefghij
I want to remove the 3rd and then the 11-18th strings, but leave a space between the two resulting strings
eg "3 abcdefgh"

I only know how to use "cut", does anyone know any way I can do this? All these strings are in the same file.

Thanks
Khoom

this is for sure hard-coded

anyway it's just a try

echo 1234567890abcdefghij | sed -e 's/\(..\)\(.\)\(.......\)\(.*\)/\2 \4/'
[~/temp]$ cat khoom.sh 
#! /bin/sh
VAL=1234567890abcdefghij
echo ${VAL:2:1} ${VAL:10}
[~/temp]$ ./khoom.sh 
3 abcdefghij
[~/temp]$ 

Hi guys,
sorry, but I amended the request at some point, but both alternatives didn't work.

Cheers
Khoom

could you please quote your sample input and the output that you are receiving which deviates the required output, so that it would be easier to look into ?

Hello Matrix,
your option is actually pretty much on course, but I modified my desired output after you helped. What you gave me will give me 3 abcdefghij, but I want 3 abcdefgh

Cheers
Ben

desired output as requested above : 3 abcdefghij

Just change vino's code to this:

#!/bin/bash
VAL=1234567890abcdefghij
echo ${VAL:2:1} ${VAL:10:8}

This seems to be limited to bash so if you are using anything else, you are better off using sed or something.

I get the error:
***
${VAL:2:1} : bad substitution
***

What shell are you using? This will only work with bash.

with slight modification,

echo 1234567890abcdefghij | sed -e 's/\(..\)\(.\)\(.......\)\(.*\)\(..\)/\2 \4/'

3 abcdefgh

just a curiosity why do you not want to use cut ?

Because cut will not leave spaces between the feilds (or will it?)

Try...

echo "1234567890abcdefghij" | awk '{print substr($0,3,1) " " substr($0,11,8)}'

Excellent Yvor, thanks!