Scripting Help

Hello All,

I am as they say " a scripting novice" and need some advice please. I am trying to create a simple script to check in log directories for specific entries within the log files. So what i thought i would do is get the user to enter the file name and date of the log file to search. I have done that, but now i have an issue. The date they input i need to use twice, once in its original format (yyyymmdd) and once again without days (yyyymm).

For example date input is 20090301 by the user. The first search i am doing (shown below) is fine but i just wonder if there is an easy way to amend the variable "logdate" as required. For the second search because of the nature of the log files i need to reduce that variable just to 200903. Can this be done easily so i can then use that amended variable to search in a different log directory??? Or would you advise doing something else (somehow) in this case.......

This is the script so far (Excluding variables set at the top);

# Input File Name and Date.
echo "\n\tInput File Name You Are Searching For:\c"
read filename
echo "\n\tDate of Log File (yyyymmdd):\c"
read logdate
echo "\n\tSearching for $filename in logs"

# Search the xferlogs directories.
grep $filename $logs1/xferlog.$logdate

Any help/advice would be appreciated as still trying to teach myself the dark art of shell scripting

You can try those

$ short_date=${logdate%??}

or 

$ short_date=`echo $logdate | cut -c-6`

You should be able to use the substr command to extract that portion out of the date you want. For example, 20080931 can be cut down in the script by assigning

logdate2=substr(logdate,1,6) for example

This will give you 200809 in logdate2.

'substr' command? What shell scripting language is that?

Thanks for the pointers.....Used the option mentioned by ce9888 and worked a treat.