need some explain about this script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need some explain about this script
# 1  
Old 03-21-2009
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
# 2  
Old 03-21-2009
if WHOLEFILENAME=filename_DD_MM_YYYY_HHMMSS.log
Then the rest of code could look like:
Code:
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
# 3  
Old 03-22-2009
Quote:
Originally Posted by dellsh
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

There's no need for an external command:

Code:
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"

# 4  
Old 04-08-2009
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
# 5  
Old 04-08-2009
I am not quite clear what you are asking for, but if you want the filename only of a file then you may do:
Code:
# basename /home/tony/testfile
testfile
#

and if you want the directory only then you may do:
Code:
# dirname /home/tony/testfile
/home/tony
#

If I have got your question wrong then please give an example of what you require.
# 6  
Old 04-09-2009
/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

Last edited by dellsh; 04-09-2009 at 07:53 AM..
# 7  
Old 04-09-2009
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)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

can someone explain shift command in script?

think using shift would help me finish my script but cant get it work without your help. would appreciate if you give me a example with shift & counter in the same script so I can later work on that to my one. Thanks and Good Luck! (1 Reply)
Discussion started by: me.
1 Replies

2. Shell Programming and Scripting

Explain this shell script code.

Hi i am new to shell script can any one please explain me the code below which is written for execution of python scripts which are located in same folder. please explain the code line by line ls *.py > xx while do read myline || break python $myline done<xx Thanks Mukthyar.... (1 Reply)
Discussion started by: mukthar1255
1 Replies

3. Shell Programming and Scripting

explain while loop in ksh shell script

#!/bin/ksh log=ABCl log=EFG log=HIJ i=0 while <------ what is the meaning of ($i - lt 3) do print ${log} (( i=i+1 )) done (1 Reply)
Discussion started by: Bperl1967
1 Replies

4. Shell Programming and Scripting

Can you please explain what this script does?

I am trying to figure out what this script does. Can someone help? delt_file=`diff /transfer/adx/tey_header.txt /transfer/adx/tey_header_yesterdy.txt` if ] ; then touch /transfer/adx/lrstb028_ctl2.ctl else if test -f "/transfer/adx/lrstb028_ctl2_2.ctl" ; then touch... (1 Reply)
Discussion started by: chamajid
1 Replies

5. Shell Programming and Scripting

Explain this AWK script plz

Hi frnds, one my frnds has given resolution for my problem as below. it working great , but i couldnt understand somethings in the script. Why ++ operator after the function calling. how these each block working. will each run for each input line sequencially or one block for all the lines... (9 Replies)
Discussion started by: Gopal_Engg
9 Replies

6. Shell Programming and Scripting

Can help me explain this script?

Hi expert Can help me explain this script? myFile="./File" myCell="" while do read myCell || break echo "" echo "***************************" echo "$myCell" echo "***************************" done < $myFile this is ksh. Can help me... (1 Reply)
Discussion started by: vincyoxy
1 Replies

7. Solaris

Pl explain the shell script code

if then ROLLBACK=1 ; elif then echo "Nothing to install!" ; echo "Exiting." ; exit 0; Plz explaing what is the ${1:-0} in if loop?:) (3 Replies)
Discussion started by: ysrikanth
3 Replies

8. Shell Programming and Scripting

Can someone explain a bubble sort in Krn script to me?

See topic. I need to understand how it works before i start to work on a program anyone have any resources or the time to explain it thanks. (5 Replies)
Discussion started by: bluesilo
5 Replies

9. Shell Programming and Scripting

explain me this shell script ...

currentSid=${TWO_TASK:-$ORACLE_SID} echo $currentSid this script returns value of ORACLE_SID but what i am not getting is what is ":-" doing ?? (1 Reply)
Discussion started by: zedex
1 Replies

10. Shell Programming and Scripting

need help to explain script

dear all, can anyone help me to explain all the commands in the .profile bourne shell below ? really appreciate ur help. PLEASE. 1 2 # @(#) $Revision: 72.2 $ 3 4 # Default user .profile file (/usr/bin/sh initialization). 5 6 # Set up the terminal: 7 if 8 then 9 eval ` tset -s -Q -m... (1 Reply)
Discussion started by: ykchua
1 Replies
Login or Register to Ask a Question