[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Skipping comments in load files

From: Mike Miller
Subject: Re: Skipping comments in load files
Date: Tue, 5 Oct 2004 23:56:07 -0500 (CDT)

On Tue, 5 Oct 2004, Joe Koski wrote:

I figured out my problem. The particular file that I picked to try as an example had a single space on the last "blank" line of the file.

I don't know how people usually deal with this kind of thing, but something like this will alter the original file 'filename' without making a copy, and it will remove all spaces and tabs from all otherwise empty lines:

perl -pi -e 's/^[ \t]+$//' filename

Is that enough to correct the problem with all files? Is it ok to have consecutive newlines (\n)? A nice thing about it is that 'filename' can include wildcard characters so that you can do things like this...

perl -pi -e 's/^[ \t]+$//' *.txt fix every file in a directory.

You can also make a script called "despacer" (or whatever you want to call it) that looks like this...

---begin script on next line-----
#!/usr/bin/perl -i -p
s/^[ \t]+$//
---end script on previous line-----

...and works like this:

despacer *.txt

Note that /usr/bin/perl must be replaced with the path to perl on your system and you must run "chmod a+x despacer" to make the file executable. Also remember that the command will alter your files without backing them up. It is possible to write the script to automatically back them up, but it is usually undesirable in this situation, I would think.

Just thought I'd toss that out there because it took me a while to discover how useful perl could be for that kind of thing and there must be someone else in this world who could profit from it.



Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]