Search code examples
bashawketlinformatica-powercenter

PowerCenter - Extract Date from source filename


I want to extract the date of an empty file , example :

Orders_05012015.txt

This, to occupy it as a variable to query the database.

select * from orders Where date = $$Date_order (05012015)

I try to do this task by command , but I only get it via examples of AWK and I'm in windows

Example via awk:

SET CompletePath=\\192.168.20.175\infa_shared\SrcFiles\CRED20102009.csv
SET JustFileName=`basename $CompletePath`
echo $JustFileName|awk -F"." '{print $1}'|awk '{print substr($1,length($1)-7, length($1))}'

Solution

  • You can use PowerShell in Windows

    $a=[io.path]::GetFileNameWithoutExtension("\\192.168.20.175\infa_shared\SrcFiles\CRED20102009.csv")
    $a.substring($a.length-8,8)