# Solved: bat file to copy variable text into other parts of a txt file



## kr1 (Feb 24, 2011)

Sorry this looks a bit long, but most of it is example data... 
I've never used a bat file, so please excuse my ignorance if this is easy to people who are more familiar with this. 

I'm not a programmer, I just have files of text data that I wish to interogate and manipulate. 

I am try ing to use a find to then go on and potentailly copy some data from a string of text where the string of text preceeding the data I wish to copy is variable. The only constants are that the first three charachters (alpha) will be constant and the string of text will have the same amount of + signs within it. 

I want to be able to populate the 6 numberics which appear after the fourth + sign onto each line below it, up to the part where you reach END=n' and continue through the file until the last END=n' is found. 


Does this make sense? If so can any one help me? Probably a bit ambitious as I've never created a .bat file before I just need to find a way of achieving this as I need the details daily from files with perhaps 20k records. 

Example data below 

Starting data 

LMN=ABC:1+BBBB:COULD SAY AN+ZSED:COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+123456+AAAAAAA+ANYVALUES+A' 
STRING OF TEXT1 
STRING OF TEXT2 
STRING OF TEXT3 
STRING OF TEXT4 
STRING OF TEXT5 
END=5' 
LMN=ABC:1+C00016IFFERENT VALUES INC SPACES+Z00123 COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+000001+AAAAAAA+ANYVALUES+A' 
STRING OF TEXT1 
STRING OF TEXT2 
STRING OF TEXT3 
END=3' 
LMN=FED:1+EDRE:COULD SAY ANYTHING INCLUDING SPACES+FERD:COULD SAY ANSPACES+DDMMYYYY:HHMMSS+9999+AAAAAAA+ANYVALUES+A' 
STRING OF TEXT1 
END=1' 
LMN=XYZ:5+BZER:ANYTHING+B456:OTHE TEXT+DDMMYYYY:HHMMSS+801207+JHYTHGH+JUHY01+T' 
STRING OF TEXT1 
STRING OF TEXT2 
STRING OF TEXT3 
STRING OF TEXT4 
STRING OF TEXT5 
STRING OF TEXT6 
STRING OF TEXT7 
STRING OF TEXT8 
END=8' 



I want this to be amended this to look like this; 

LMN=ABC:1+BBBB:COULD SAY AN+ZSED:COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+123456+AAAAAAA+ANYVALUES+A' 
123456 STRING OF TEXT1 
123456 STRING OF TEXT2 
123456 STRING OF TEXT3 
123456 STRING OF TEXT4 
123456 STRING OF TEXT5 
END=5' 
LMN=ABC:1+C00016IFFERENT VALUES INC SPACES+Z00123 COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+000001+AAAAAAA+ANYVALUES+A' 
000001 STRING OF TEXT1 
000001 STRING OF TEXT2 
000001 STRING OF TEXT3 
END=3' 
LMN=FED:1+EDRE:COULD SAY ANYTHING INCLUDING SPACES+FERD:COULD SAY ANSPACES+DDMMYYYY:HHMMSS+999999+AAAAAAA+ANYVALUES+A' 
999999 STRING OF TEXT1 
END=1' 
LMN=XYZ:5+BZER:ANYTHING+B456:OTHE TEXT+DDMMYYYY:HHMMSS+801207+JHYTHGH+JUHY01+T' 
801207 STRING OF TEXT1 
801207 STRING OF TEXT2 
801207 STRING OF TEXT3 
801207 STRING OF TEXT4 
801207 STRING OF TEXT5 
801207 STRING OF TEXT6 
801207 STRING OF TEXT7 
801207 STRING OF TEXT8 
END=8'


----------



## Ent (Apr 11, 2009)

We do have a few people who are good at batch files and I'm sure someone can come up with a solution.
However it would be much more useful if you gave us real or imaginary sample data, "could say anything" actually makes things harder to understand.
Also could you put it in [Co de][/co de] (without the space in "code") tags around your sample. That prevents long lines such as the LMN= lines from wrapping which makes it easier to see what's going on.


----------



## TheOutcaste (Aug 8, 2007)

Does the line with the number you want always start with LMN?
Is the 4th character always the equals sign?
Same question with the END line
Do any other lines start with LMN or END?
Example, if a line starts with *Ended* that would be a problem, unless the equals sign is always the 4th character on the lines that mark the end.
Are those three letters always upper case? Lowercase? Unknown case?
Do any lines start with a semicolon? (*;*)
Do any lines contain an exclamation point (*!*), a percent sign (*%*), or an odd number of double quotes (*"*)?
Is there always a plus sign after the number?
are there any lines (even blank ones) between the *End=* and the next *LMN=* line?
Are there blank lines in the files that need to be preserved?

Do you want to change *9999* to *999999* as you did, or was that a typo?

```
LMN=ABC:1+BBBB:COULD SAY AN+ZSED:COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+[COLOR=Red]123456[/COLOR]+AAAAAAA+ANYVALUES+A'
STRING OF TEXT1
STRING OF TEXT2
STRING OF TEXT3
STRING OF TEXT4
STRING OF TEXT5
END=5'
LMN=ABC:1+C00016:DIFFERENT VALUES INC SPACES+Z00123:D COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+[COLOR=Red]000001[/COLOR]+AAAAAAA+ANYVALUES+A'
STRING OF TEXT1
STRING OF TEXT2
STRING OF TEXT3
END=3'
LMN=FED:1+EDRE:COULD SAY ANYTHING INCLUDING SPACES+FERD:COULD SAY ANSPACES+DDMMYYYY:HHMMSS+[B][COLOR=Red]9999[/COLOR][/B]+AAAAAAA+ANYVALUES+A'
STRING OF TEXT1
END=1'
LMN=XYZ:5+BZER:ANYTHING+B456:OTHE TEXT+DDMMYYYY:HHMMSS+[COLOR=Red]801207[/COLOR]+JHYTHGH+JUHY01+T'
STRING OF TEXT1
STRING OF TEXT2
STRING OF TEXT3
STRING OF TEXT4
STRING OF TEXT5
STRING OF TEXT6
STRING OF TEXT7
STRING OF TEXT8
END=8'
```


```
LMN=ABC:1+BBBB:COULD SAY AN+ZSED:COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+123456+AAAAAAA+ANYVALUES+A'
[COLOR=Red]123456[/COLOR] STRING OF TEXT1
[COLOR=Red]123456[/COLOR] STRING OF TEXT2
[COLOR=Red]123456[/COLOR] STRING OF TEXT3
[COLOR=Red]123456[/COLOR] STRING OF TEXT4
[COLOR=Red]123456[/COLOR] STRING OF TEXT5
END=5'
LMN=ABC:1+C00016:DIFFERENT VALUES INC SPACES+Z00123:D COULD SAY ANYTHING INCLUDING SPACES+DDMMYYYY:HHMMSS+000001+AAAAAAA+ANYVALUES+A'
[COLOR=Red]000001[/COLOR] STRING OF TEXT1
[COLOR=Red]000001[/COLOR] STRING OF TEXT2
[COLOR=Red]000001[/COLOR] STRING OF TEXT3
END=3'
LMN=FED:1+EDRE:COULD SAY ANYTHING INCLUDING SPACES+FERD:COULD SAY ANSPACES+DDMMYYYY:HHMMSS+[B][COLOR=Red]9999[/COLOR][COLOR=Blue]99[/COLOR][/B]+AAAAAAA+ANYVALUES+A'
[B][COLOR=Red]9999[/COLOR][COLOR=Blue]99[/COLOR][/B] STRING OF TEXT1
END=1'
LMN=XYZ:5+BZER:ANYTHING+B456:OTHE TEXT+DDMMYYYY:HHMMSS+801207+JHYTHGH+JUHY01+T'
[COLOR=Red]801207[/COLOR] STRING OF TEXT1
[COLOR=Red]801207[/COLOR] STRING OF TEXT2
[COLOR=Red]801207[/COLOR] STRING OF TEXT3
[COLOR=Red]801207[/COLOR] STRING OF TEXT4
[COLOR=Red]801207[/COLOR] STRING OF TEXT5
[COLOR=Red]801207[/COLOR] STRING OF TEXT6
[COLOR=Red]801207[/COLOR] STRING OF TEXT7
[COLOR=Red]801207[/COLOR] STRING OF TEXT8
END=8'
```


----------



## kr1 (Feb 24, 2011)

Thanks for your comments, the 9999 was a typo, should have said 999999.

I've found the answer. 

Many thanks


----------



## TheOutcaste (Aug 8, 2007)

Perhaps you could share the answer you found so others may benefit.

And, if your issue has been resolved you can mark this thread Solved by using the *Mark Solved* button at the Top Left of this thread (above the first post) 









Opps, looks like ya already did mark it solved.

Jerry


----------

