Solved

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

Posted on 2016-10-05
3
68 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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