MATLAB Answers

0

Read specific string from multiple .txt file and output in new .txt file

Asked by Ching Jisheng on 13 Oct 2018 at 5:29
Latest activity Commented on by madhan ravi on 14 Oct 2018 at 1:44

HI, I m new here. I would like to ask, if I m gonna read specific string from hundreds of text file and store in new text file, how do I write the script?

The example of text format. (file name Test001.txt,Test002.txt,...Test135.txt)

 10  AASF 9812RM332    2122473.12345 -1234567.55534  1123051.96747    W      GR
 11  ABAS 538FTX521    1234567.54702  9746229.17771 -6123685.19960    A      GR
 12  AC15 D1245S991   -1409634.35734 -8523961.59795  1230562.45682
 13  ACOR 1ASD15121    3459812.56699 -6798367.34574  4357066.68268

I wanna extract only whole string contain AC15 and save to new text file continuously from all 135 file.

Example of output.

 12  AC15 D1245S991   -1409634.35734 -8523961.59795  1230562.45682
 12  AC15 D1245S991   -1409634.31237 -8523961.52411  1230562.45251
 12  AC15 D1245S991   -1409634.32351 -8523961.58532  1230562.41251

  0 Comments

Sign in to comment.

1 Answer

Answer by madhan ravi on 13 Oct 2018 at 6:08
 Accepted Answer

fid=fopen('sample.txt','r')
file=textscan(fid,'%s  \n','Delimiter','')
fclose(fid)
file{1}{3}

  3 Comments

see the link: processing sequence of files

AllFiles=dir('*.txt'); %just specify the format correctly

Sign in to comment.