cut command issue from a line of text

Hi,
I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut command it excludes the spaces and I got wrong result.

LINE="AX80633030PHLIAD20209 1010104711411153             0054          000050000      11  PHLIAD1013112320100134-0003+003007000103+0033ER4ER4037012 N835HK0698D7   A2           A2E     05201011302010113020101130201011300000500000240000000TETE20101130NN8063201011300925IAD0004800045     5"
STR1=`echo $LINE | cut -c 86-88`
echo $STR1

It simply does not work. Can you pl help me with any alternative solution ?

Regards
Asutosh

You don't need to run a whole command to get a substring, the shell has a builtin for it. This will be roughly one hundred times faster.

LINE="AX80633030PHLIAD20209 1010104711411153             0054          000050000      11  PHLIAD1013112320100134-0003+003007000103+0033ER4ER4037012 N835HK0698D7   A2           A2E     05201011302010113020101130201011300000500000240000000TETE20101130NN8063201011300925IAD0004800045     5"
echo "${LINE:86:3}"

...however, the data you want does not appear to be at position 86 anyway. (If the line has tabs in it, this may be a source of confusion since those would post as spaces on this board.) What do you actually want from this line?

LINE="AX80633030PHLIAD20209 1010104711411153 0054 000050000 11 PHLIAD1013112320100134-0003+003007000103+0033ER4ER4037012 N835HK0698D7 A2 A2E 05201011302010113020101130201011300000500000240000000TETE20101130NN8063201011300925IAD0004800045 5"
echo $LINE|awk '{print substr($0,86,3)}'

No, they do not work. I am getting error with the code echo "${LINE:86:3}". It says "${LINE:89:3}": The specified substitution is not valid for this command.

However the awk is working and giving me wrong result. There is no tab character - all spaces.
Thanks
Asutoshch

awk's default delimiter is space and tab. So above awk should work.
A possible correction could be using double quotes around the LINE variable:

echo "$LINE"|awk '{print substr($0,86,3)}'

If it doesn't work, Pls post input and output data OR whatever result you get (And expected out)

@asutoshch
When you have a Shell problem, please state what Operating System you are running and what Shell you are using.
If you have an expected output, please tell us what you expect as the output.

Anyway based on your code, this should work in most circumstances. Always put double quotes round string variables whether it is necessary or not.

LINE="AX80633030PHLIAD20209 1010104711411153 0054 000050000 11 PHLIAD1013112320100134-0003+003007000103+0033ER4ER4037012 N835HK0698D7 A2 A2E 05201011302010113020101130201011300000500000240000000TETE20101130NN8063201011300925IAD0004800045 5"
STR1=`echo "$LINE" | cut -c 86-88`
echo "$STR1"

003