[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

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

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
paulie99
Asked:
paulie99
  • 9
  • 8
  • 7
  • +1
1 Solution
 
QlemoC++ DeveloperCommented:
(for /F "delims==" %%L in ('myfile.txt') do echo %%L) > newfile.txt
0
 
sirbountyCommented:
Shouldn't that read:
(for /F "delims==" %%L in (c:\myfile.txt) do echo %%L=) > newfile.txt
0
 
QlemoC++ DeveloperCommented:
It should.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
paulie99Author Commented:
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
 
sirbountyCommented:
Well, you've just altered your initial criteria.
Perhaps a full description with examples so that there's no further confusion...?
0
 
paulie99Author Commented:
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
 
sirbountyCommented:
"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
 
paulie99Author Commented:
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
 
sirbountyCommented:
Have you tested the above?  Is it not working?  Works on my test here...
0
 
paulie99Author Commented:
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
 
sirbountyCommented:
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
 
QlemoC++ DeveloperCommented:
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
 
paulie99Author Commented:
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
 
QlemoC++ DeveloperCommented:
You should be able to extend my "example" to those strings
0
 
sirbountyCommented:
Qlemo has your solution above - just needs to be updated to reflect these latest additions...
0
 
paulie99Author Commented:
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
 
QlemoC++ DeveloperCommented:
Put it into a batch file.
0
 
paulie99Author Commented:
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
 
QlemoC++ DeveloperCommented:
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
 
paulie99Author Commented:
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
 
sirbountyCommented:
question is still in progress.
0
 
QlemoC++ DeveloperCommented:
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
 
paulie99Author Commented:
thanks Qlemo have a good weekend
0
 
QlemoC++ DeveloperCommented:
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
 
t0t0Commented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 8
  • 7
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now