Jump to content

Merge two files


coles
 Share

Recommended Posts

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 :)

 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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?

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
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?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...