Find and Replace text in other txt file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mazius123
Posts: 6
Joined: 23 Mar 2012 08:56

Find and Replace text in other txt file.

#1 Post by mazius123 » 07 Apr 2012 06:35

Hello all :) , maybe there was more topics about this nor i can imagine. but maybe someone can help me with this one again :wink: ... , so lets go through the work table. i want that when i change the version variable in the bat file (the variable with version) would search for "imperial" (after that text there is the version numbers) in text file for example : System_folder/plugins/sometextfile.txt and replace the version with newer or the same.

hope you understand what i said :roll:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find and Replace text in other txt file.

#2 Post by foxidrive » 07 Apr 2012 07:08

mazius123 wrote:Hello all :) , maybe there was more topics about this nor i can imagine. but maybe someone can help me with this one again :wink: ... , so lets go through the work table. i want that when i change the version variable in the bat file (the variable with version) would search for "imperial" (after that text there is the version numbers) in text file for example : System_folder/plugins/sometextfile.txt and replace the version with newer or the same.

hope you understand what i said :roll:


Sorry, it is not very clear.

It seems that you have a file:
System_folder/plugins/sometextfile.txt

and inside it there is text like this for V1.12
imperial 1.12

You want to change the "imperial 1.12" to "imperial 1.13" for example, is that right?

mazius123
Posts: 6
Joined: 23 Mar 2012 08:56

Re: Find and Replace text in other txt file.

#3 Post by mazius123 » 07 Apr 2012 07:34

foxidrive wrote:
mazius123 wrote:Hello all :) , maybe there was more topics about this nor i can imagine. but maybe someone can help me with this one again :wink: ... , so lets go through the work table. i want that when i change the version variable in the bat file (the variable with version) would search for "imperial" (after that text there is the version numbers) in text file for example : System_folder/plugins/sometextfile.txt and replace the version with newer or the same.

hope you understand what i said :roll:


Sorry, it is not very clear.

It seems that you have a file:
System_folder/plugins/sometextfile.txt

and inside it there is text like this for V1.12
imperial 1.12

You want to change the "imperial 1.12" to "imperial 1.13" for example, is that right?


Yes, you are at the right wave. "imperial 1.12" as you said the variable is "imperial %1.13%" so how can i do this with batch ? maybe some more brains will help me out this thing ? :D

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find and Replace text in other txt file.

#4 Post by foxidrive » 07 Apr 2012 08:05

This is untested and uses SED:

Use the batch file like this: ChangeVer.bat 1.13

It expects the I of Imperial to be in column one, and it is case sensitive.

@echo off
sed "s/^Imperial.*/Imperial %1/" "System_folder/plugins/sometextfile.txt" >"System_folder/plugins/sometextfile.txt2"
move /y "System_folder/plugins/sometextfile.txt2" "sometextfile.txt"

mazius123
Posts: 6
Joined: 23 Mar 2012 08:56

Re: Find and Replace text in other txt file.

#5 Post by mazius123 » 07 Apr 2012 08:24

foxidrive wrote:This is untested and uses SED:

Use the batch file like this: ChangeVer.bat 1.13

It expects the I of Imperial to be in column one, and it is case sensitive.

@echo off
sed "s/^Imperial.*/Imperial %1/" "System_folder/plugins/sometextfile.txt" >"System_folder/plugins/sometextfile.txt2"
move /y "System_folder/plugins/sometextfile.txt2" "sometextfile.txt"


Thanx for this, but maybe someone know better way to do this, and i still think there is many more ways to do this (and easier / more creative). so if someone have better ideas in heads maybe post here huh ? :roll:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find and Replace text in other txt file.

#6 Post by foxidrive » 07 Apr 2012 08:32

mazius123 wrote:Thanx for this, but maybe someone know better way to do this, and i still think there is many more ways to do this (and easier / more creative). so if someone have better ideas in heads maybe post here huh ? :roll:


You use the :roll: icon in strange ways.

If you tell us *exactly* what you want done then I'm sure people can help you further. You see, using approximate information often gets you approximate solutions. Capishe?

Post Reply