need some explain about this script

Dear Member,
i need help in this script
filename_DD_MM_YYYY_HHMMSS.log
this is the log file format
i need to split this name to three variables
1 variables contain filename
2 variables contain _DD_MM_YYY_
3 variables contains HHMMSS

and print the three variables
thanks for you attention

if WHOLEFILENAME=filename_DD_MM_YYYY_HHMMSS.log
Then the rest of code could look like:

FILENAME=`echo ${WHOLEFILENAME} | awk -F"_" '{ print $1 }'`
FILEDATE=`echo ${WHOLEFILENAME} | awk -F"_" '{ print "_"$2"_"$3"_"$4"_" }'`
FILETIME=`echo ${WHOLEFILENAME} | awk -F"_" '{ print $5 }' | awk -F"." '{ print $1 }'`

There are clever ways of doing all that in one line, but I like the keep it simple method!

HTH

Tony Fuller

There's no need for an external command:

name=filename_DD_MM_YYYY_HHMMSS.log
filename=${name%%_*}
temp=${name#"$filename"_}
ddmm=${temp%_*}
temp=${temp#*"$ddmm"_}
hhmmss=${temp%.log}

printf "Filename = %s\n" "$filename"
printf "   DD_MM = %s\n" "$ddmm"
printf "  HHMMSS = %s\n" "$hhmmss"

hi Tony how are you
first very thanks for your reply
and sorry for late but some health issue
second
this filename format LOG_FILE_`date '+%d_%m_%Y_%H%M%S'`.log
if i want to do this:-
i have a directory /export/home/dell/log contain a log file
# ls -ltr /export/home/dell/log/*_%d_%m_%Y_* >> /export/home/dell/LogsFor_05_04_2009
# awk -F" " '{print $9}' somelog
by this way i select the last columan only i select the path of the file only
i want to enter every line into script i make it

thanks in advance

I am not quite clear what you are asking for, but if you want the filename only of a file then you may do:

# basename /home/tony/testfile
testfile
#

and if you want the directory only then you may do:

# dirname /home/tony/testfile
/home/tony
#

If I have got your question wrong then please give an example of what you require.

/export/home/dell/log
Is a directory contain log file the filename format as this
Example:-
Filename_08_04_2009_0800.log

1- I want to select file *_05_04_2009_* and _06_04_2009_* and sort all file by time stamp to know which is run first and what is the second
2- Redirect the output to file

Aside:
If you are at design stage,
filename_YYYY_MM_DD_HHMMSS.log
would be easier to deal with than
filename_DD_MM_YYYY_HHMMSS.log

Questions:
How many files in directory /export/home/dell/log ?

Are there any subdirectories under /export/home/dell/log ? (This question is about using unix "find").

Is every file in directory /export/home/dell/log of the form:
filename_DD_MM_YYYY_HHMMSS.log ?

Is the file timestamp the same as the time in the file name?

Are there any underscore "_" or full stop "." or space " " characters in any "filename" string?

Is indexing these logs a one-off exercise or will it be run once per day at the end of each day (for example)?

I Design This Step

more than 10000 files

no subdirectories only files

the all of the under /export/home/dell/log with this format
LOG_FILE_`date '+%d_%m_%Y_%H%M%S'`.log

i make this step when i generate i log file t write the status the only thing is difference is the time stap and date couse off of this file is running every week and i have similler file will check and make log every day
for example:-
checkconnect_20_03_2007_180231.log
checkconnect_21_03_2007_180231.log
checkconnect_22_03_2007_180231.log

some files have "_" and some files not

i didn't know what you are take about

Note:
for the first thing i want to make script
# script.bash _DD_MM_YYYY_ _DD_MM_YYYY_
select files which created in the two date and sort it by time stamp this make redirection into file is my main problem
data where select from the following path /export/home/dell/log

file name format is the following
LOG_FILE_`date '+%d_%m_%Y_%H%M%S'`.log

Question:-
# find /export/home/dell/log -name *_20_04_2009_*
the out of this command give me the file sorted by the time stamp
is that right or i make some thing wrong

and if i hope to make this command
# find /export/home/dell/log -name *_20_04_2009_* and *_21_04_2009_* sorted also by time stamp what is the syntex of the command