Logic for Extracting Substrings

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Logic for Extracting Substrings

Post by Pavan_Yelugula »

Hi All
I am trying to find a set of files with extension .zip from a file folder. I am working around a DOS Script for this which is doing a lot of other functionality..
For some wierd reason when i code in my DOS Script the following Syntax
dir /a-d|find ".zip" It is giving me an error saying
Result = find: unable to access ".zip": The system cannot find the file specified.
The same syntax works fine from the Command Prompt... :evil:

Never the less the command dir /b works which is giving me all the files in the directory in short form...
Is there Some String function in Datastage which will Slit through the whole directory brought by dir /b and give me only the names which fit an Pattern like '.zip'...
I am not able to use Field or any other commands as there are no delimeters

Any help will be really appreciated

Thanks
Pavan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Logic for Extracting Substrings

Post by chulett »

Pavan_Yelugula wrote:Syntax
dir /a-d|find ".zip" It is giving me an error saying
Result = find: unable to access ".zip": The system cannot find the file specified.
The same syntax works fine from the Command Prompt... :evil:
You are probably not in the directory you think you are in. Are you using fully qualified paths or at least doing a 'cd' to the directory in question before issuing the 'dir' command? A 'cd' that you are sure isn't failing, that is?
Pavan_Yelugula wrote:Is there Some String function in Datastage which will Slit through the whole directory brought by dir /b and give me only the names which fit an Pattern like '.zip'...
I am not able to use Field or any other commands as there are no delimeters
Sure there is. The 'dot' in the filename can typically be used as the delimiter for the Field command... would that not work for you?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

I am doing a CD before i fire the Dir command and i am seeing the files i want to see when i do the dir /b...

And yes the '.' can be used as a delimiter cool :idea:

My dir /b is giving this output

Code: Select all

Count1.txt
Count2.txt
Temp.zip
FTPScript_New.bat
Temp1.zip
In this i want only Temp.zip and Temp1.zip to be returned... Any ideas how i can get them

Thanks
Pavan
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Hi Pavan,

Why no just using

Code: Select all

dir *.zip
. Also what i remeber is that your Find command should have directory path in which it has to search for that .zip file. Something like

Code: Select all

Find dir /a-d "*.zip"
or might be just add that "*" and try it.
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

dir /b | find ".zip" should work just fine from DOS as long as you are sure you are in the right directory. Not sure what else the issue might be. :?

Or just do dir /b *.zip instead.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Hi aslam and chulett
i am using dir /a-d | find ".txt" in my script....
The error is a bit wierd like "CANN'T ACCESS .TXT"... :shock:
Never the less the dir /b *.zip is working... :)
Thanks a lot guys

Thanks
Pavan
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

As noted, just try dir /a-d|find "zip" without the '.', which may be condisired as delimiter.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Kumar,

Nope it gives the same error

Code: Select all

Result = find: unable to access "zip": The system cannot find the file specified. 
Thanks
Pavan
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

"*.zip" will not work though. It looks for exact string. Just for testing purpose, find if you were able to get the output for "dir /a-d" alone. If thats ok, then check if this gives all the list of files.

Code: Select all

dir /a-d | find " "
ie., search for a space.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Still i think there is something not quite correct with your FIND syntax.


Check this:

http://www.computerhope.com/findhlp.htm
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

aslam
The same command works perfectly fine on my command prompt but the moment i take it in to Datastage it is messing up...

Kumar dir /a-d works but the moment i put in "find" it is not working...

Thanks
Pavan
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Could you plaste the code that you use in your script. Make be the "|" piping is not happening as expected.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
us1aslam1us
Charter Member
Charter Member
Posts: 822
Joined: Sat Sep 17, 2005 5:25 pm
Location: USA

Post by us1aslam1us »

Remove the quotes and try it .
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Find expects a string which need to be enclosed in quote.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Hi Kumar
This is a small part of the code in my script for this logic nothing hi-fi

Code: Select all

E:
cd \cdw\dev\Script
dir /a-d|find "zip"
Same set of commands works fine on comand prompt but doesn't when called from datastage... i wonder as you said it is with the pipe..

Thanks
Pavan
Post Reply