Cut Command value assign to variable

Hi,
I am new to UNIX Scripting. I have been trying to use the CUT command to retrieve part of the header from a file and assign it to a variable. I have tried searching a lot, but I am still unsuccessful.

Sample Header: HJAN BALANCE 20090616
I need to retrieve the date here, which always ranges from the 18-25 position.

All I am trying to do is:

echo "Header Line: $headerLine"
headerDate = cut -c18-25 ${headerLine}

Here $headerLine has a valid value. But the command doesnt work.

Kindly assist.

Thanks,
Raghu

Try...

headerDate=`cut -c18-25 ${headerLine}`

Thank you Rakesh.
I tried this. Below is the response:

Header Line: HJAN BALANCE 20090616
cut: cannot open HJAN
cut: cannot open BALANCE
cut: cannot open 20090616
Launch_LKW-Gen.ksh[136]: headerDate: not found
Header Date:

Try...

headerDate=$(expr substr "${headerLine}" 18 8)

Following is the response:

Header Line: HJAN BALANCE 20090616
expr: syntax error

Does it have to do with the double quotes?

headerDate=`echo $headerLine | cut -c18-25`

Amit,
This option worked. But the results are not as expected and also varies for different inputs. Kindly take a look:

Header Line: HJAN BALANCE 20090616
Header Date: 0616
Header Line: HJAN HOLDING 20090616
Header Date: 0616
Header Line: HJAN CASHLEDGER20090616
Header Date: 090616

My mistake

headerDate=`echo ${headerLine} |cut -c18-25`

Results are not as expected because you are not having date from columns 18 to 25...Earlier you said, it is fixed.

I got the reason after I posted the previous one. The separators between the three values is a TAB and not multiple spaces. I realized when I pasted the output here. There is only one space now, which is actually a TAB.

May be I should use the -d option and retrieve the 3rd value?

Following is the content of the first line of the file:
HJAN BALANCE 20090616

echo $headerLine | cut -d ' ' -f3 | cut -c5-8

If the date is in third column and each column is separated by white space.

Thank you Amit, this helped.

The possible inputs are following:
HJAN BALANCE 20090616
HJAN HOLDING 20090616
HJAN CASHLEDGER20090616

Hence it worked for the first two. Hence I feel in my case the best approach would be to retrieve the last 8 characters. But since there are trailing spaces, I need to first trim the line then retrieve the last 8.

Makes sense?