Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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