Jump to content
Macro Express Forums

Estract Data From Multiple Txt And Join Together


xillao

Recommended Posts

Every week i need to get some information from mutiple text files which is always preceded by "Input rate :" and " Output rate : ". It will be like this

 

Input rate : 1111111 bps

 

Output rate : 2222222 bps

 

And I only need 1111111 and 2222222

 

and send them to a excel file (or text file) in two columns. One for Input Rate and another for Output Rate.

 

Thanks in advance

Link to comment
Share on other sites

I´ll try (sorry, my english is not the best). I have multiple txt files and each file in the middle of other text this kind information

 

Input rate : 1402096 bps (873 pps)

Output rate : 4659616 bps (1088 pps)

 

And I only need the data which is preceeded by "Input rate:" and "output rate:". This information for example 1402096 3434344 343434 3434434 etc (estracted from the txt files) send it to a unique file (txt or excel). If it´s possible, one column with the numbers estracted from "Input rate :" field and another column for the numbers estracted from "Output rate :" field. Like this

 

Example of origin data txt file for macro

 

MSERVICE@ADFED> show interfaces fe7-8-8

Input rate : 1402096 bps (873 pps)

Output rate : 4659616 bps (1088 pps)

 

 

New file created after macro

 

Input output

1402096 562634

4659616 742560

1467047 704692

7075471 465964

 

Thanks, your help is very appreciated

Link to comment
Share on other sites

First off let me say this is simple and if you just need to get it done and don’t have time to learn I’m available for hire. Also a macro like this would only take a matter of minutes to write so it would be pretty cheap.

 

In this case what I would suck the entire text file into a text variable and then use the Variable Set Integer command and Get Position of Text in a Variable. Then add the number of characters to get to the space in front of the first digit of your number. For Input Rate :” I think the value is 13. Now I would delete that first part of the variable and do another Get Position to find the position of the first space which should be the first space after the number decrement it once and now Copy Part of Text to get your number!

 

Variable Set String %T1% from File: "test.txt"
Variable Set Integer %N1% from Position of Text in Variable %T1%
Variable Modify Integer: %N1% = %N1% + 12
Variable Modify String: Delete Part of %T1%
Variable Set Integer %N1% from Position of Text in Variable %T1%
Variable Modify Integer: Dec (%N1%)
Variable Modify String: Copy Part of %T1% to %T1%

 

<TVAR2:01:04:c:\test.txt><IVAR2:01:13:1:Input rate :><NMVAR:01:01:1:0000001:2:0000012><TMVAR2:11:01:00:001:N01:><IVAR2:01:13:1: ><NMVAR:09:01:0:0000001:0:0000000><TMVAR2:10:01:01:001:N01:>

 

You would simply add another chunk to the above code to do Output to a different variable. Now just save your variables to a file using Variable Modify String. Look on the second tab for those commands.

 

You might check out my CRLF & TAB macro on my webpage. It can help you build a file.

 

Like I said I'd be happy to write somethign for you too. You could send me some sample files and I can have you up and running in no time. Also I can teach you how I did it so you can tweak it later yourself.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...