coles

Merge two files

13 posts in this topic

Hi guys 

I am new to Autoit. I would like to Automate a task which i do 

at the moment i am running a batch file which creates a1.txt,a.txt 

as shown below

netsh mbn show interface dump > c:\temp\a.txt
C:\Users\admin>ipconfig /all > c:\temp\a1.txt

and then i have to open the cmd prompt to merge both files

with the command below


Open command prompt in folder c:\temp
for %f in (*.txt) do type "%f" >> Audit.txt

which merges both text files into 1,which is working perfectly(minus the time waste remote logging into every system to combine the file).

 

Can someone help out to make the whole thing automated.

Gathering details from netsh and ipconfig then merging the result

 

Thanks for the comments :)

 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you change the redirector for your ipconfig command to >> it will append the results to the text file.

netsh mbn show interface dump > c:\temp\a.txt
ipconfig /all >> c:\temp\a1.txt

 

This page may have some useful information for you regarding command line execution and output redirection. 

Edited by spudw2k
1 person likes this

Share this post


Link to post
Share on other sites

@spudw2k Awesome thanks for that, i will try merging the files with a snippet.  

Share this post


Link to post
Share on other sites

@spudw2k i Ended up using 

netsh mbn show interface dump >> c:\temp\a.txt & ipconfig /all >> c:\temp\a.txt

so that it puts both results to 1 file.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

be careful.  >> causes output to append to a file.  > overwrites the contents of a file.

If you only use >> your file will grow, and grow, and grow.  You should still use > for the netsh dump and >> for ipconfig to create a "fresh" file each run.

Edited by spudw2k
1 person likes this

Share this post


Link to post
Share on other sites
7 hours ago, spudw2k said:

be careful.  >> causes output to append to a file.  > overwrites the contents of a file.

If you only use >> your file will grow, and grow, and grow.  You should still use > for the netsh dump and >> for ipconfig to create a "fresh" file each run.

@spudw2k Thanks for the guidance, i have changed the  batch file into Auto it as below

Example1()

Func Example1()

    RunWait(@ComSpec & " /c " & "netsh.exe mbn show interface dump > c:\temp\a.txt");
    RunWait(@ComSpec & " /c " & "ipconfig /all >> c:\temp\a.txt");
        EndFunc

is this rite way to put it in autoit or it needs more conditioning?

Share this post


Link to post
Share on other sites

@spudw2k can you please help me with one more query

i have a.txt file with (only) content <vehicle>100</vehicle>, is it possible to remove <vehicle></vehicle> and just keep the 100 .

 

Share this post


Link to post
Share on other sites

Yes cole there is multiple ways of doing this.

Example Code:
 

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <String.au3>

; This give you the file handle and open the file to read
$fileid = FileOpen("a.txt")

; This read the first line of the file and store it on $fileline variable.
$fileline = FileReadLine($fileid, 1)

; Return an Array with your value in the first position.
$value = _StringBetween($fileline,">","<")

; Get that value from the first position.
$finalvalue = $value[0]

MsgBox("","","The value inside a.txt and between  <vehicle> and </vehicle> is: "&$finalvalue)

You can do this in another way using StringLeft or StringRight and then you dont need to use an array.

About your merge file thing, if you do that at certain Time you could code something that check the date and time and make that for you and send you an email with the resulting file and you don't need to Log In or do anything on the remote computer.

Important Note: Before you ask simple questions make sure you search on the Help file, is everything there.
People here answering your questions are doing this like volunteers so don't expect this people code for you.

Happy Coding.

Kind Regards
Alien

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

  1.  
Edited by MaxPlankpar

Share this post


Link to post
Share on other sites
3 hours ago, MaxPlankpar said:

"Merge my files" crams files together nicely.

A bit erroneous for concatenating text files though, wouldn't you agree?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now