Solved

(MSDOS) Remove text after an equal sign in a file

Posted on 2009-04-03
26
495 Views
Last Modified: 2012-08-13
I need a batch script to run on XP that will delete the text after the equal sign in a set file.  For example in a file I have two lines:
version-title=test
 version-main=9.0.0.0025
I want to delete everything after the equal sign. One is this possible through MSDOS and two how can I do it?
All suggestions welcome.
0
Comment
Question by:paulie99
  • 9
  • 8
  • 7
  • +1
26 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 24060493
(for /F "delims==" %%L in ('myfile.txt') do echo %%L) > newfile.txt
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24060535
Shouldn't that read:
(for /F "delims==" %%L in (c:\myfile.txt) do echo %%L=) > newfile.txt
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24060609
It should.
0
 

Author Comment

by:paulie99
ID: 24060644
thats a  great script but I need to automate as this will be part of a build script, so is there a way of specifying the lines that you want to remove text after the equal sign.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24060659
Well, you've just altered your initial criteria.
Perhaps a full description with examples so that there's no further confusion...?
0
 

Author Comment

by:paulie99
ID: 24060703
mmh I have given examples of the lines I need changed, the only confusion is that i did not state I was looking for automation.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24060716
"is there a way of specifying the lines that you want to remove "

that's the new piece, from the way I interpret it.
Are you saying now that you want to selectively choose certain lines to be filtered?  If so, under what condition.
Otherwise, the above 'is' indeed automated...plug it into a batch file and go...if you need help scheduling it or something, let us know.
0
 

Author Comment

by:paulie99
ID: 24060794
version-title=test
version-main=9.0.0.0025
No the lines in the files will be set lines as the in the ones above, the text or numbers after the equal sign are subject to change, so they will be wildcard. I will call the batch file from another, so need to worry abouut that.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24060811
Have you tested the above?  Is it not working?  Works on my test here...
0
 

Author Comment

by:paulie99
ID: 24060893
No I just ran it and it removed the text after all the equal signs as I have stated i want it to remove  onlty set lines and not everything.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24060923
Sorry - still confused...(might help if you can post a sample file).
In your file, you have these lines:
version-title=test
version-main=9.0.0.0025
along with many other lines that contain = that you don't want removed?

If that's the case - what's the criteria for these two?  Will they always be the first 2 lines?  Will they always be version-title & version-main?  Need something to go on to correctly code this...
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24060986
My complicated solution is

(for /F "delims=" %%F in (myfile.txt) do echo %%F | findstr /b "version-title= version-main=" >nul && (echo %%F | for /F "delims==" %%L in ('more') do echo %%L=)  || echo %%F) > newfile.txt

Open in new window

0
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

 

Author Comment

by:paulie99
ID: 24061034
Ok sample file attached that I wll need to update. The lines that I need to change are:
version-scc-comment=Nightly-Build
version-title=full
ersion-main=9.0.0.0025
version-main-comma=9,0,0,0025
The text before the equal sign will not change, but the text after the equal sign could be anything as users check this file in on a constant basis. Therefore I need a MSDOS batch script that will remove all the text after the equal sign for these lines ONLY, all others should be left as is as they rarely ever change.
build.txt
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24061063
You should be able to extend my "example" to those strings
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24061069
Qlemo has your solution above - just needs to be updated to reflect these latest additions...
0
 

Author Comment

by:paulie99
ID: 24061182
Whenever i run the script
(for /F "delims=" %%F in (myfile.txt) do echo %%F | findstr /b "version-title= version-main=" >nul && (echo %%F | for /F "delims==" %%L in ('more') do echo %%L=)  || echo %%F) > newfile.txt
my file looks like below, which is not what I was looking for:
C:\test>echo ###############################################################################   | findstr /b "version-title= version-main="   1>nul  && (echo ###############################################################################   | for /F "delims==" %L in ('more') do echo %L= )  || echo ###############################################################################
###############################################################################

C:\test>echo #   | findstr /b "version-title= version-main="   1>nul  && (echo #   | for /F "delims==" %L in ('more') do echo %L= )  || echo #
#

C:\test>echo #   XIAM VERSION NUMBERS   | findstr /b "version-title= version-main="   1>nul  && (echo #   XIAM VERSION NUMBERS   | for /F "delims==" %L in ('more') do echo %L= )  || echo #   XIAM VERSION NUMBERS
#   XIAM VERSION NUMBERS

C:\test>echo #   Edit this file before doing a release.   | findstr /b "version-title= version-main="   1>nul  && (echo #   Edit this file before doing a release.   | for /F "delims==" %L in ('more') do echo %L= )  || echo #   Edit this file before doing a release.
#   Edit this file before doing a release.

C:\test>echo #   When finished changes, simply save and close to resume build process   | findstr /b "version-title= version-main="   1>nul  && (echo #   When finished changes, simply save and close to resume build process   | for /F "delims==" %L in ('more') do echo %L= )  || echo #   When finished changes, simply save and close to resume build process
#   When finished changes, simply save and close to resume build process

C:\test>echo #   | findstr /b "version-title= version-main="   1>nul  && (echo #   | for /F "delims==" %L in ('more') do echo %L= )  || echo #
#

C:\test>echo #   If you are doing an official release, this file will be checked in   | findstr /b "version-title= version-main="   1>nul  && (echo #   If you are doing an official release, this file will be checked in   | for /F "delims==" %L in ('more') do echo %L= )  || echo #   If you are doing an official release, this file will be checked in
#   If you are doing an official release, this file will be checked in

C:\test>echo #   with the following comment:   | findstr /b "version-title= version-main="   1>nul  && (echo #   with the following comment:   | for /F "delims==" %L in ('more') do echo %L= )  || echo #   with the following comment:
#   with the following comment:

C:\test>echo #   | findstr /b "version-title= version-main="   1>nul  && (echo #   | for /F "delims==" %L in ('more') do echo %L= )  || echo #
#

C:\test>echo       version-scc-comment = fdffd   | findstr /b "version-title= version-main="   1>nul  && (echo       version-scc-comment = fdffd   | for /F "delims==" %L in ('more') do echo %L= )  || echo       version-scc-comment = fdffd
      version-scc-comment = fdffd

C:\test>echo #   | findstr /b "version-title= version-main="   1>nul  && (echo #   | for /F "delims==" %L in ('more') do echo %L= )  || echo #
#
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24061406
Put it into a batch file.
0
 

Author Comment

by:paulie99
ID: 24061456
I have run all the scripts in a batch and get the same as above, I'm considering closing this question and starting again as I'm getting no where fast.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24061539
That would be very unpolite to just close the question to re-post after 1.25 hrs!
Give me a second to check again ...

0
 

Author Comment

by:paulie99
ID: 24061575
I appreciate the feedback i have been given but I'm paying for a service and I'm looking for a quick turn around.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24061674
question is still in progress.
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 24061769
Ok, this now works, tested with your file. There was some confusion because of the space before equal sign.

@echo off

(for /F "delims=" %%F in (build.txt) do echo %%F | findstr /c:"version-title=" /c:"version-main =" >nul && (echo %%F | for /F "delims==" %%L in ('more') do @echo %%L=)  || echo %%F) > build-new.txt

Open in new window

0
 

Author Closing Comment

by:paulie99
ID: 31566261
thanks Qlemo have a good weekend
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24061828
I urge you to delete your duplicated question http://www.experts-exchange.com//Q_24292870.html for the same thread, as this one is not closed.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24066480
WOW!!! That's an awesome one-liner! It's difficult enough to code the logic to perform the task at hand yet alone code it as a single line!

I am truly mesmerised...

Qlemo, I've said this before and I'm saying it again. You are the top man. Your code is an example of excellence in batch file programming.

My only criticism is you're not paid for your expertise.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
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…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

708 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

20 Experts available now in Live!

Get 1:1 Help Now