John,
There's a simpler way... (perl is, typically, overkill.)
To strip the blanks from a file, just use "sed":
cat $file | sed "s/ *$//" > /tmp/strip.$$
mv /tmp/strip.$$ $file
This cats the file named "$file" - strips the blanks and writes
the output in the file named /tmp/strip.$$. Then, it moves
the file named strip.$$ back over the original file.
The sed substitution can be read as:
substitute any string of blanks, anchored at the end of the
line with "nothing".
You can also do a similar trick to get rid of MSDOS carriage
returns... very straightforward.
- Dave R. -
John McKown wrote:
>
> Is there a simple way to strip blanks from all the lines in a file? What I
> am doing is downloading members from my various PDSes. Some of these member
> contain the "standard" sequence number in columns 73-80. I am using Perl to
> strip these off. After stripping off the sequence numbers, I would like to
> strip off any resulting trailing blanks. My current Perl script looks like:
>
> #!/usr/bin/perl
> while(<>) {
> chop;
> s/(.{0,72}).*/\1/;
> $new1 = reverse($_);
> $_ = $new1;
> s/ *(.*)/\1/;
> $new = reverse($_);
> print $new,"\n";
> }
>
> I admit that I'm a tyro Perl person. I'm a legacy mainframer. I am more used
> to assembler and REXX.
>
> --
> John McKown
> Senior Systems Programmer