Link to home
Start Free TrialLog in
Avatar of paulie99
paulie99

asked on

(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.
Avatar of Qlemo
Qlemo
Flag of Germany image

(for /F "delims==" %%L in ('myfile.txt') do echo %%L) > newfile.txt
Shouldn't that read:
(for /F "delims==" %%L in (c:\myfile.txt) do echo %%L=) > newfile.txt
It should.
Avatar of paulie99
paulie99

ASKER

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.
Well, you've just altered your initial criteria.
Perhaps a full description with examples so that there's no further confusion...?
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.
"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.
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.
Have you tested the above?  Is it not working?  Works on my test here...
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.
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...
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

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
You should be able to extend my "example" to those strings
Qlemo has your solution above - just needs to be updated to reflect these latest additions...
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 #
#
Put it into a batch file.
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.
That would be very unpolite to just close the question to re-post after 1.25 hrs!
Give me a second to check again ...

I appreciate the feedback i have been given but I'm paying for a service and I'm looking for a quick turn around.
question is still in progress.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks Qlemo have a good weekend
I urge you to delete your duplicated question https://www.experts-exchange.com/questions/24292870/MSDOS-delete-text-after-equal-sign-in-a-file.html for the same thread, as this one is not closed.
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.