If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > korn shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-24-05, 17:53
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
korn shell script

hello.,

i have 2 files..

1 file is in this folder

/home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544
(this part)

other file is in this folder

/home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100
(this part)

i have to compare both the files using "20050713211544" ( this part)and "20050711210100"
and then which ever is greatest i have to move that file only
to the following folder : /home/pav/testdata


i have to write the above in a ksh script.

can anyone help me please !!!

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-25-05, 01:56
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
use basename to get the filename and then do a if fn1 > fn2
Reply With Quote
  #3 (permalink)  
Old 10-25-05, 08:51
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
korn shell script

hello.,

thanks..i can use the basename to get the file. but the file comparision has to be done by 20050711210100 (the middle part after WLG..) AND THEN decide which one is greater and then moved to a different folder.

since both the source files are in different folders can basename be used to bring the files from those folders and then do the comparison. i am having difficulty in using those.

Thanks
Reply With Quote
  #4 (permalink)  
Old 10-25-05, 09:56
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
korn shell script

I tried with the basename but it did not work out.
can anyone help me in answering my query please

thanks
Reply With Quote
  #5 (permalink)  
Old 10-25-05, 12:59
asram asram is offline
Registered User
 
Join Date: Jul 2003
Posts: 34
Comparison of file created times

Pavan,

I understand you need to compare two files based on thier cration times and delete the older one...correct me if I am wrong.

you can use "-ot" to compare the times and move the one which you have to the folder.
Reply With Quote
  #6 (permalink)  
Old 10-25-05, 13:03
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
korn shell script

Hello.,

yes i need to compare 2 files ( both in different folders) based on their creation date and which ever is greatest i have to move that file to another folder.

what is "ot"

thanks
Reply With Quote
  #7 (permalink)  
Old 10-25-05, 13:06
asram asram is offline
Registered User
 
Join Date: Jul 2003
Posts: 34
Or use the following code:

file1="/home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544"
file2="/home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100"

file1date=`echo $file1 | cut -d"/" -f5 | awk '{FS="."; print $2}'`
file2date=`echo $file1 | cut -d"/" -f5 | awk '{FS="."; print $2}'`

if [ $file1date -gt $file2date ]
then
mv $file1
else
mv $file2
fi

I have not tested the code though..but it should work..
Reply With Quote
  #8 (permalink)  
Old 10-25-05, 13:10
asram asram is offline
Registered User
 
Join Date: Jul 2003
Posts: 34
Sry..I din't see your posting..
If it is just to compare use "-ot" with the full pathnames..
ot stnads for older than.

if [ /a/b/c/file1 -ot /a/d/c/file2 ]
then
mv /a/b/c/file1 /tmp/
else
mv
/a/d/c/file2 /tmp/
Reply With Quote
  #9 (permalink)  
Old 10-25-05, 14:17
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
korn shell script

the script that you sent me is working.

thegreatest file is found based on number 20050713211544 and 20050711210100 ( this is present after the WLG in the file) and the output has to move to a folder.

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On