I need to extract a 8 characters between known and copy value to clipboard

0

I am not a superuser but more of a supertinkerer. I would like to take a text file, a CNC program to be exact, and extract an 8 digit string from between the known characters of "TxxxxxxxxM6" where T and M6 are known and never change nor do the amount of digits between them. I would use any method reasonable for a newb. I have many files with many tool changes and I want to be able to extract the tool change calls from the nc file and then paste them into text editor or spreadsheet in Windows. Using Windows 10.

Thanks in advance!!!

Jeremy W.

Posted 2017-05-23T02:47:59.770

Reputation: 9

Welcome to SU. What format is the text file? Is it a CSV? Can you post an example of how it is formatted? – wysiwyg – 2017-05-23T02:56:31.157

format is programname.nc or programname.eia but the extension can be changed to anything if .txt were needed. – Jeremy W. – 2017-05-23T03:03:06.523

can i upload a file? – Jeremy W. – 2017-05-23T03:03:16.703

file will always be similar to this: – Jeremy W. – 2017-05-23T03:07:33.780

(PGM,="943352T)
:128G0G71F3810.T10039401M6 (MSG, ******** ROUGH MILL DATUM -B- B2 LOAD B90 ) G0X-155.Y94.8Z70.231B90.F600.S800T10030001H2M3 Z0.561 G1X0. G2X81.Y13.8I0J13.8 G0Z70.231 Q55 :131G0G71F715.T10030001M6 (MSG, ********ROUGH MILL DATUM -E- A LOAD B180 ) G0X120.958Y18.1Z65.867B180.F485.S765T40043701H5M3 G11E[PCD,5,A]=0L100 M2
– Jeremy W. – 2017-05-23T03:08:58.900

Can you upload the file here: https://uploadfiles.io/

– wysiwyg – 2017-05-23T03:15:01.370

1

If your data spans multiple lines, it would much easier to see the actual layout of your data if you put the example in your original post and then made it into a code block, so that the original format is retained, which you can do by enclosing the block of lines within backtick characters. If you click on "help", you will see information on how you can format your posts and comments. You might be able to use substring extraction within a for loop of a batch file, but I'm unsure of the actual layout of your data.

– moonpoint – 2017-05-23T03:20:30.350

Answers

0

You can easily do this in Excel, if it is in a format that you can easily import it into Excel. Assuming you have all the data in column A, just put this formula in cell B1 and double click the fill handle to copy it down the whole column:

=MID(A1,2,8)

The MID function returns the specified number of characters from a given string, and given starting point. In this case, it takes the string in cell A1, and returns 8 characters, starting from the character 2.

EDIT: Seeing the way the data is formatted, this may not work for you. You would have to first have the "TxxxxxxxxM6" string in its own column

wysiwyg

Posted 2017-05-23T02:47:59.770

Reputation: 2 313

0

One way to find the tool changes is to search for them in an editor. On eway:

  1. Install notepad++
  2. Open your file in Notepad++
  3. Ctrl-F to find
  4. Make sure the regular expression box is checked
  5. Search for T........M6

Stephen Rauch

Posted 2017-05-23T02:47:59.770

Reputation: 2 455