Scan and change a specific number in a text file?

4 ビュー (過去 30 日間)
Joey Cavale
Joey Cavale 2017 年 7 月 20 日
コメント済み: Joey Cavale 2017 年 7 月 20 日
My problem is this, I have thousands of CNC G code text files I need to scan through that have a different part number in each file. Every part number begins with a 1 and is a 5 digit long integer (Ex. 11569 or 14355). Is there any way that I can search a text file for the part number?

採用された回答

Elias Gule
Elias Gule 2017 年 7 月 20 日
How about this:
filename = 'Item.txt';
% Read the text from file
filetext = fileread(filename);
% Set the search pattern for a part number
searchPattern = '((?<=\()(1\d{4}))';
% Search the text
partnos = regexp(filetext,searchPattern,'match','dotexceptnewline'); % A cell array of part no.s
  1 件のコメント
Joey Cavale
Joey Cavale 2017 年 7 月 20 日
Works great! Thanks Elias

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by