Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2005
    Posts
    92

    Unanswered: 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

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    use basename to get the filename and then do a if fn1 > fn2

  3. #3
    Join Date
    Oct 2005
    Posts
    92

    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

  4. #4
    Join Date
    Oct 2005
    Posts
    92

    korn shell script

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

    thanks

  5. #5
    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.

  6. #6
    Join Date
    Oct 2005
    Posts
    92

    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

  7. #7
    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..

  8. #8
    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/

  9. #9
    Join Date
    Oct 2005
    Posts
    92

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •