Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe01.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to remove unwanted text from a .txt file?
References: <gbbqun$qo5$1@fred.mathworks.com> <ryeCk.36464$QF5.28064@newsfe08.iad> <gbbubd$2n7$1@fred.mathworks.com>
In-Reply-To: <gbbubd$2n7$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 34
Message-ID: <VGfCk.562$Cl1.66@newsfe01.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe01.iad 1222215477 24.79.146.116 (Wed, 24 Sep 2008 00:17:57 UTC)
NNTP-Posting-Date: Wed, 24 Sep 2008 00:17:57 UTC
Date: Tue, 23 Sep 2008 19:18:42 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:491674


Cy abd top-posted:

Please do not post your reply above the material you are commenting on: it makes
it difficult to hold a discussion.

>> perl, sed, ed, awk, grep, C, matlab, ...

> how about just the matlab way, since I'm posting in the matlab forum? care to
> maybe hint on that?

The matlab way that -I- would use would be to write a short perl script to do
the work. Matlab arrives with perl installed, accessible via the perl() command.

For example, put this in file allbut.pl

$refuse = shift @ARGV; while (<>) { print unless /(?:$refuse)/o; }


Then to use it, in matlab call with (e.g.)

filteredtext = perl('allbut.pl', 'Lost data connection|Reconnecting', 'XYZ.txt');

where XYZ.txt is the file name of the file to have the lines removed,
and the lines to be deleted are any lines that contain either the string
'Lost data connection' or the string 'Reconnecting' anywhere on the line.

The result variable, filteredtext, would probably be a char vector
(with embedded end of line characters) containing all the -other- lines.
You could write that to a file if you wanted, or it might be more convenient
to textscan() the string without writing it out to a file.


The same task can certainly be done without calling out to perl, but
it is more of a nuisance.