LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Extracting Part of String

    Employee
    Posted 06-15-2015 11:49

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jchartrand

    I have been playing with the left/right function trying to find a way to pull this information out of the string.

    My file names are all formatted the same, and I want to pull the bolded portion below from my string into a new field that I can then format into a date (M/D/CCYY).

    Any help would be greatly appreciated!

    FileName
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Calgary_10_22_2014 3_58_12 PM_DuplicatesPurgedByUser_INTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Calgary_10_7_2014 12_55_24 PM_DuplicatesPurgedByUser_EXTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Calgary_10_7_2014 12_55_29 PM_DuplicatesPurgedByUser_INTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Calgary_10_7_2014 12_55_30 PM_DuplicatesPurgedByUser_EXTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Calgary_10_7_2014 12_55_30 PM_DuplicatesPurgedByUser_INTRAFILE.txt


  • 2.  RE: Extracting Part of String

    Employee
    Posted 06-15-2015 12:08

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Put this code into a filter node, and it should work for you.

    part1=FileName.split("/")   #split filename into pieces
    fn=part1[len(part1)-1]      #get last part of filename (without path)
    
    part2=fn.replace(" ","_").split("_")   #replae blanks and split on underscores
    d=date(part2[4].long(),part2[2].long(),part2[3].long())   #assemble date
    if part2[8]=="PM" then offset=12 else offset=0            #deal with AM/PM
    t=time(part2[5].long()+offset,part2[6].long(),part2[7].long())   #assemble time with AM/PM offset
    
    emit *,d,t


  • 3.  RE: Extracting Part of String

    Employee
    Posted 06-15-2015 12:57

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jchartrand

    Thanks for the response.

    I tried altering to get it to work with no luck. One thing I may have left out is that the date wil not always be in the same spot depending on the length of the distribution id prior.

    I received the error:

    could not convert to long integer: 'Ontario'
    Node execution terminated while processing data by error:
    could not convert to long integer: 'Ontario'

    Provided a few additional lines from other distributor id's to show the differences.

    FileName
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Calgary_10_7_2014 12_55_24 PM_DuplicatesPurgedByUser_EXTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Central Ontario_9_6_2014 6_54_36 AM_DuplicatesPurgedByUser_EXTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Central Ontario_9_6_2014 6_54_43 AM_DuplicatesPurgedByUser_EXTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Central Ontario_9_6_2014 6_54_50 AM_DuplicatesPurgedByUser_INTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Southwestern Ontario_10_22_2014 3_58_27 PM_DuplicatesPurgedByUser_INTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Southwestern Ontario_10_24_2014 9_16_56 AM_DuplicatesPurgedByUser_EXTRAFILE.txt
    I:\Corp\Department\Foodbuy TRX\Foodbuy TRX files-Canada\TransactionExport/Sysco Southwestern Ontario_10_7_2014 1_17_35 PM_DuplicatesPurgedByUser_EXTRAFILE.txt


  • 4.  RE: Extracting Part of String

    Employee
    Posted 06-15-2015 13:00

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jchartrand

    Going to go ahead and ask what may be a dumb question....

    Not sure if this is easier, but am I able to filter on my directory node for files that have a date modified from last month?


  • 5.  RE: Extracting Part of String

    Employee
    Posted 06-15-2015 13:32

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ltolleson

    Yes, you can use the stat() function to get information about the file. Simply take the output of the Directory Node and put it into a filter and use the code below in your filter node.

    
    fileStats = 'FileName'.stat()
    
    
    fileBytes = fileStats.getItem(0)
    fileCreationDate = timestamp(long(fileStats.getItem(1) * 1000))
    fileModifiedDate = timestamp(long(fileStats.getItem(2) * 1000))
    
    
    modifiedLastMonth = if fileModifiedDate.dateSubtract(date(), "months").abs() == 1 then true else false
    
    
    emit *, fileBytes, fileCreationDate, fileModifiedDate
    where modifiedLastMonth


  • 6.  RE: Extracting Part of String

    Employee
    Posted 06-15-2015 13:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ryeh

    Hi, Josh. Try the following with regular expressions (regex).

    I modified Stony's approach to account for changes in the name. The approach assumes that there will be no spaces after the AM/PM. Also, the time offset is 12 when it's PM but the hour is less 12, i.e. 12:01pm is still 12:01.
    Attachments:
    getDateTime.brg


  • 7.  RE: Extracting Part of String

    Employee
    Posted 06-16-2015 05:26

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: jchartrand

    Thanks Roger & Stony!

    Both of these worked great and provide multiple approaches to resolve.