copy with regular expression how to

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
warrentolentino
Posts: 9
Joined: 02 Oct 2014 11:54

copy with regular expression how to

#1 Post by warrentolentino » 11 Jan 2018 08:52

i have these 2 files

NY_20180110_082629.xml
NY_20180110_082629_response.xml


and i have a basic command like

copy /y NY_<SysDate.yyyymmdd>_<SysTime.HH>*.xml e:\Apps

that command is actual run from the tool called tidal software which is basically a job scheduling software.

what happens is that both files are being copied together. i need only to copy the first file which is the NY_20180110_082629.xml and exclude the 2nd file NY_20180110_082629_response.xml. basically the file that i need to copy the file is the NY_<yyyymmdd>_<hhmmss>.xml format.

please advise. thank you.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: copy with regular expression how to

#2 Post by Squashman » 11 Jan 2018 09:44

Did you try removing the asterisk?

warrentolentino
Posts: 9
Joined: 02 Oct 2014 11:54

Re: copy with regular expression how to

#3 Post by warrentolentino » 11 Jan 2018 09:59

yes and it will not work because if I removed the wildcard (asterisk) it will translate to
NY_20180110_08.xml

the file is in NY_20180110_082629.xml

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: copy with regular expression how to

#4 Post by Squashman » 11 Jan 2018 10:21

This is really out of scope for DosTips.com. Your problem is with the scheduling software you are using and has nothing to do with Windows batch files or other Windows Scripting Languages.

I bet if you read the user guide you would find your answer.

warrentolentino
Posts: 9
Joined: 02 Oct 2014 11:54

Re: copy with regular expression how to

#5 Post by warrentolentino » 11 Jan 2018 10:46

actually it is the scheduling tool that execute the windows command. i supply the windows command to the scheduling tool and it will execute it.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: copy with regular expression how to

#6 Post by Squashman » 11 Jan 2018 10:53

warrentolentino wrote:
11 Jan 2018 10:46
actually it is the scheduling tool that execute the windows command. i supply the windows command to the scheduling tool and it will execute it.
The variables you are using are coming from the Tidal. So in essence you are working within the confines of the Tidal Scheduling software. I don't think we have too many subject matter experts on that software around here.
Cisco has a community forum that you can get help with for all their products.
https://supportforums.cisco.com/t5/tida ... enterprise

warrentolentino
Posts: 9
Joined: 02 Oct 2014 11:54

Re: copy with regular expression how to

#7 Post by warrentolentino » 11 Jan 2018 11:02

Squashman wrote:
11 Jan 2018 10:53
The variables you are using are coming from the Tidal. So in essence you are working within the confines of the Tidal Scheduling software. I don't think we have too many subject matter experts on that software around here.
Cisco has a community forum that you can get help with for all their products.
https://supportforums.cisco.com/t5/tida ... enterprise
that is true the variables are coming from tidal but does not mean that is is confine to tidal. its a long explanation how the variables work but i have used it countless of times in conjunction with the windows command and is not a problem. but to make it short the variable <SysDate.yyyymmdd>_<SysTime.HH> is translated into:
20180110_08
it will stop right there without the wildcard because the command "copy /y NY_<SysDate.yyyymmdd>_<SysTime.HH>.xml e:\Apps" will translate to
copy /y NY_20180110_08.xml e:\Apps

anyway on the command line i tried different approach using a findstr:


dir /b NY_20180110_* | findstr /i /r "[0-9$].xml"
fndstr.jpg
fndstr.jpg (80.86 KiB) Viewed 8562 times
on the windows command line i tried to use the dir with combination of findstr command. it was able to find the file that i am looking for. the last part was that how can i use that result to the copy command. so i can copy that file to another folder.

i tried this but it looks like the command is not right

R:\>copy NY_20180110_* | findstr /i /r "[0-9$].xml" sample_file.xml
FINDSTR: Cannot open sample_file.xml

R:\>

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: copy with regular expression how to

#8 Post by thefeduke » 11 Jan 2018 13:48

Here is a batch script that may do what I think you wanted. It only ECHOs the copy command.

Code: Select all

@echo off & setlocal
    Set "SysDATE=20180110" 
    Set "SysTIME=08" 
    For /F "usebackq tokens=* delims=" %%F in (
        `dir /b NY_%SysDATE%_%SysTIME%* ^| findstr /i /r "[0-9$].xml"` 
    ) do Set "File=%%~F" 
    Echo.copy %File% e:\Apps
    Pause 
John A.

kwsiebert
Posts: 42
Joined: 20 Jan 2016 15:46

Re: copy with regular expression how to

#9 Post by kwsiebert » 12 Jan 2018 09:11

warrentolentino wrote:
11 Jan 2018 09:59
yes and it will not work because if I removed the wildcard (asterisk) it will translate to
NY_20180110_08.xml
Please include information like this in your initial request. While it was probably likely that <SysTime.HH> expanded to the 08 in the file names, making assumptions in code is a great way to cause horrible problems, so we need as much information as possible. Now, with this new information, if you are still constrained to the Tidal application I can suggest trying:

Code: Select all

copy /y NY_<SysDate.yyyymmdd>_<SysTime.HH>????.xml e:\Apps

Post Reply