windows scripting to search a value in '.HL7' file [closed] - batch-file

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Through windows batch file, I am trying to -
a. open a folder > open latest '.hl7. file (by date) in the folder.
b. search a specific value in the file. e.g value of the key 'name'
c. echo the value.
I am new to scripting, Can anybody help me write a script for the same?

I am not sure about the format of the HL7 files but this will get the most latest HL7 file into env variable MyFile and then print the lines in the file that have "name" in them.
#set MyFile=
#for /F %%I in ('dir /od /b *.hl7') do set MyFile=%%I
#if defined MyFile find "name" %MyFile%
If HL7 has many different formats you may be better off writing a program that uses an HL7 library to parse your file.
I hope this helps you get started.

Related

Script to execute .bat files and move them to a different folder [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a program that creates .bat files to c:\temp.
I need to create a script that runs each .bat file inside c:\temp and moves them to c:\temp\backup after a successful execution.
How can i achieve this?
Thank you
The following code can be a good starting point.
Use the for loop to enumerate the files with .bat extension in the given directory.
Use the call command to execute.
Use the move command to move the file to other directory.
Update: As suggested in the comments, I added a basic error checking if the call command succeeded and only in the case of success, I am moving the bat file.
#echo off
set myDir=C:\temp\bats
set doneDir=C:\temp\bats\done\
md %doneDir%
for %%I in ("%myDir%\*.bat") do (
call %%I
if %ERRORLEVEL% == 1 (
move %%I %doneDir%
) else (
echo "error moving - %errorlevel%"
)
)

Batch - Trying to read a text file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make a batch file that will read a text file (Net.txt) to pull a datapath from it. Assign it to a variable then empty a file from a nearby location.
Net.txt looks like
SharedPath=C:\Program\2017\
SharedUNC=C:\Program\2017\
Then find the directory and delete files with a specific extension.
cd %variable%\OPTION\trash
DEL *.xxx
This works great locally when everything is on C: but I don't think batch/cmd supports UNC paths. Is there a better language to use?
To read a file line by line, use a for /f loop.
The following code assumes net.txt to be exactly as shown in your question and will delete the files in both the SharedPath and the SharedUNC (should they differ; if they are the same, del will spit an error for the second one (which you can suppress with 2>nul))
for /f "tokens=2 delims==" %%a in (net.txt) do del "%%aOPTION\trash\*.xxx"
If that is not what you want, please describe your problem in more detail.

Extract zip contents into directory with same name as zip file, retain directory structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I would like to write a bat script to do the following:
Use 7 Zip to extract files from an existing zip file, into a folder by the same name as the original zip file (bar the .zip extension), and keeping the file & directory structure that was contained in the zip file.
I can extract all the same files into the current directory, by using
"C:\Program Files (x86)\7-Zip\7z.exe" e myZipFile.zip
Reading the help of the 7z-command by just typing "C:\Path To\7-Zip\7z.exe" gets the help with all possible arguments. Here we find the following interesting ones:
e : Extract files from archive (without using directory names)
and
x : eXtract files with full paths
Trial and error shows that the latter is the one fitting your desired behaviour without bigger effort :)
After the comment by #BadmintonCat here is the addition that will create a folder to zip everything into (use as batch script with the file as argument):
#echo off
SET "filename=%~1"
SET dirName=%filename:~0,-4%
7z x -o"%dirName%" "%filename%"
From the help: -o{Directory} : set Output directory. 7z will create the directory if it does not already exist.
Just use the command: 7z x *.zip -o\*

how to remove the batch file you just used [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I remove a batch file I just used with a batch code line?
Like a code that does this:
remove thisbat.bat
Thanks in advance.
Some people will tell you to just put
DEL "%~f0"
on the last line, but that usually causes an error in that the BAT file can no longer find itself. You should use the following statement on the last line of your BAT file, because after it hits this line your BAT file is gone:
start /b "" cmd /c del "%~f0"&exit /b
This will launch a new delete process within the same console, thus eliminating any "file can no longer be found" errors.

Reading a txt line by line in a batch file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am driving myself crasy trying to read this txt file in a batch file:
Binary CapabilityDescriptions Caption Availability
TRUE Intel(R) Active Management Technology - SOL (COM3) 2
TRUE Intel(R) Active Management Technology - SOL (COM4) 2
TRUE Intel(R) Active Management Technology - SOL (COM5) 2
I am trying to get the the COM number if the Caption contains the string "Intel".
Try this:
#echo off
setlocal
for /f "tokens=4 delims=()" %%a in ('findstr "Intel(R)" findintel.txt') do echo %%a

Resources