Replace text in file by batchfile (calculate)

October 1, 2010 at 02:15:17
Specs: Windows XP/7, min 1.8 Ghz
I have a file witch looks like this :

[Groups]
NumGroups=3
NumFiles=53207
Group1=Test1.GRP
Group2=Test2.GRP
Group3=Test3.GRP

I want to create a new file by batch witch automaticly increases the NumGroup with 1 (Numgroups=4,It has to actually read the value and add 1)
Futhermore it has to add a line at the end of the file like GroupX=END.GRP, were X has the same value as the Numgroups count

Thanks in advance.
Jeffrey


See More: Replace text in file by batchfile (calculate)

Report •


#1
October 1, 2010 at 03:54:31
download gawk for windows then do this

C:\test>gawk -F"=" "/NumGroups/{$2+=1;n=$2}{print}END{print \"Group\"n\"=END.GRP\"}" OFS="=" file
[Groups]
NumGroups=4
NumFiles=53207
Group1=Test1.GRP
Group2=Test2.GRP
Group3=Test3.GRP
Group4=END.GRP

GNU win32 packages | Gawk


Report •

#2
October 1, 2010 at 04:09:29
Thank you for your reply.

Since I have to use the batchfile on different places (USB thumbdrive) on systems where I don't want to install anything I prefer a solution without Gawk.

Best regards,
Jeffrey


Report •

#3
October 1, 2010 at 04:43:29
download gawk ONE TIME only. Its only a .exe file. Put it inside your usb and bring anywhere.

GNU win32 packages | Gawk


Report •

Related Solutions

#4
October 1, 2010 at 06:51:45
I did download gawk, but I can't get it to work.
The (text)file that should be altered is called GROUPS.TXT and is located in directory
y:\Groups\02_Jef\%DateStamp%\
gawk is located in directory y:\Groups\~Batch\

I altered the code like this :

y:\Groups\02_Jef\%DateStamp%\GROUPS.TXT>y:\Groups\~Batch\gawk -F"=" "/NumGroups/{$2+=1;n=$2}{print}END{print \"Group\"n\"=END.GRP\"}" OFS="=" file
pause

The only thing it does, is opening the GROUPS.TXT file (with Wordpad) and thats it.

What am I doing wrong ?

Best regards,
Jeffrey


Report •

#5
October 1, 2010 at 07:12:37
you did not follow my example. Did you see the "file" in my gawk example? That should be substituted for your GROUP.txt file path.

y:\Groups\~Batch\gawk -F"=" "/NumGroups/{$2+=1;n=$2}{print}END{print \"Group\"n\"=END.GRP\"}" OFS="="  y:\Groups\02_Jef\%DateStamp%\GROUPS.TXT

GNU win32 packages | Gawk


Report •

#6
October 1, 2010 at 07:41:56
Thank you !

Sorry, I didn't look good enough
Now I'm a little closer to my goal.
The code displays the correct text on screen, but now I have to capture it in a file.

Jeffrey


Report •

#7
October 1, 2010 at 08:52:03
Did find it.

> "Text.txt"

Thank you !

Jeffrey


Report •

Ask Question