Delete trailing garbage chars from a set of files?

  • Thread starter Patrick Flaherty
  • Start date
P

Patrick Flaherty

Hi,

When I copy a text file from VMS to Windows (via PATHworks) there are often
(depending on the length of the file) trailing garbage characters. I've
determined these to be byte value x1a (that it, hex 1a).

I can delete these from a single file with:

perl -p0777 -i.bu -e 's/\x1a+$//g' use.lis

What happens when I copy over a whole bunch of *.lis, many of which might have
this problem?

I can loop over all these with:

@list = glob("*.lis");
foreach $name (@list) {
print $name . "\n";
}

That prints all the names out. But what I want to do is delete the garbage
chars from each file in turn.

This doesn't work (not surprising):

@list = glob("*.lis");
foreach $name (@list) {
s/\x1a+$//g $name;
}

Doubtless I'm doing something daft here. Hope someone can help me out.

pat
 
B

Bart Lateur

Patrick said:
When I copy a text file from VMS to Windows (via PATHworks) there are often
(depending on the length of the file) trailing garbage characters. I've
determined these to be byte value x1a (that it, hex 1a).

I hope those only happen in text files? Because in that case,
DOS/Windows is capable of ignoring the rest of the file... In fact, in
perl, when binmode() has not been applied to a filehandle, perl will see
this as the end of the file.

Anyway... Can you find out the exact file length on the original system,
externally? In that case, you could use truncate() to shorten the file.
See "perldoc -f truncate".
 
P

Patrick Flaherty

Bernard,

Haven't done perl in a while, and I did try what you suggest. I believe this
works on Unix, however *.lis (again, surprisingly) doesn't seem to work on
Windows.

pat


Patrick said:
Hi,

When I copy a text file from VMS to Windows (via PATHworks) there are
often (depending on the length of the file) trailing garbage
characters. I've determined these to be byte value x1a (that it, hex
1a).

I can delete these from a single file with:

perl -p0777 -i.bu -e 's/\x1a+$//g' use.lis

What happens when I copy over a whole bunch of *.lis, many of which
might have this problem?

[...]


Doubtless I'm doing something daft here. Hope someone can help me
out.


Just change:


perl -p0777 -i.bu -e 's/\x1a+$//g' use.lis


into:


perl -p0777 -i.bu -e 's/\x1a+$//g' *.lis
 
P

Patrick Flaherty

Thanx to everyone that replied.

This is what worked for me. Like a charm. Thanx Tad.

Was I just hallucinating (I don't think so) or why does feeding *.lis to a
cmd-line invocation of perl _on Windows_ not work?

pat
 
T

Tad McClellan

Patrick Flaherty said:
This is what worked for me. Like a charm. Thanx Tad.


You can pay me back by learning to quote your followups properly.

Please do not post in backwards-time fashion.



[ snip TOFU ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top