Batch to edit copy/paste text between files

Microsoft Windows xp professional w/serv...
July 19, 2010 at 06:17:34
Specs: Windows XP, Intel Duo Core/2GB

Hi
I have one text file that looks something like this. (text1.txt)
=================================
%type-cli

wpa set password Cybershot1

%cli_end
=================================

I have another text file that will include one single random password. (text2.txt)
I want to create a batch file that will open text2, copy the word and then open text1 and replace the current password "Cybershot1" with the copied word.


See More: Batch to edit copy/paste text between files

Report •


#1
July 19, 2010 at 06:26:11
download gawk for windows (see my sig), then use this one liner


C:\test>more password
mypassword

C:\test>more template
=================================
%type-cli

wpa set password Cybershot1

%cli_end
=================================

C:\test>gawk "FNR==NR{p=$0;next}/password/{$NF=p}1" password template
=================================
%type-cli

wpa set password mypassword

%cli_end
=================================

GNU win32 packages | Gawk


Report •

#2
July 20, 2010 at 01:06:52
Thanks Ghostdog.
This looks like what i'm looking for. This is a stupid question, but I cant get the gawk to work. It is installed but I'm not sure how to launch it. On CMD it says 'gawk' is not recognized

Thanks


Report •

#3
July 20, 2010 at 01:24:21
Nevermind. I failed to change the path. Got GAWK working. Trying the solution now

Report •

Related Solutions

#4
July 20, 2010 at 01:36:43
Hi Ghostdog
It works exalty like you instructed on the Command Prompt. But when I open the template.txt file it is still on Cybershot1.
Is it possible to save the result in the text file?

Report •

#5
July 20, 2010 at 01:40:38
use output direction >> to a temp file. Then rename it back to original. This is basic OS operation, so i will leave it to you to try yourself.

GNU win32 packages | Gawk


Report •

#6
July 20, 2010 at 03:07:57
Thanks. I need it to be automated. I'll try including it the a macro. Will let you know.

Report •

#7
July 20, 2010 at 03:47:04
Thanks Ghostdog

That worked perfectly.


Report •


Ask Question