Solved

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

Posted on 2016-10-05
3
38 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 23

Expert Comment

by:NVIT
Comment Utility
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
Comment Utility
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 23

Accepted Solution

by:
NVIT earned 500 total points
Comment Utility
No problem. It works here.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
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 …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now