Solved

DOS bat file - what is easiest way to strip a string from a file

Posted on 2016-10-05
3
53 Views
Last Modified: 2016-10-06
I need to strip "main=" from a file using a dos command/bat file - what is easiest way to do that?

main=1539769350|Specimen A contains 2.5 mL ...
 main=1539719992|Original diagnosis :...
 main=1539699576|7-year-old male with...
0
Comment
Question by:Dianna Gibbs
  • 2
3 Comments
 
LVL 24

Expert Comment

by:NVIT
ID: 41831009
Hi Dianna.
If this is related to your other recent post change the last line in my code from:
echo main=!main!

Open in new window

...to
echo !main!

Open in new window


Sorry I didn't fix that in that post. 8-)
0
 

Author Comment

by:Dianna Gibbs
ID: 41831055
Great thanks, yes, same question.  I had to change line "if defined" as well - this work - see any problems with it?

@echo off
setlocal enabledelayedexpansion

set FName=\\childrens.med\app\Informatica\CERNER\FixFile.dat

for /f "tokens=*" %%a in ('type "%FName%"') do (
   set tail=%%a
   echo "!tail!" | findstr /c:"|">nul
   if !errorlevel! equ 0 (
      if defined MainIsSet echo !main!
      set main=!tail!
      set MainIsSet=1
   ) else (
      set main=!main!!tail!
   )
)
echo !main!
0
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 41831074
No problem. It works here.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question