Solved

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

Posted on 2016-10-05
3
78 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 25

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 25

Accepted Solution

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 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