Unix Scripting Question

Chris Purcell redhat at cjp.us
Tue May 4 16:07:26 UTC 2004


> I thought we were talking about trailing whitespace at the end of the
> actual filenames, such as this...
>
> touch "/root/some file with trailing whitespace     "
>
> Is that your problem, or do you have trailing whitespace in your a.lst
> file, such as...
>
> "/etc/samba/smb.conf    "


Nevermind my last post, I misread what you said.  I wrote another Perl
script that will fix your a.lst file removing the trailing whitespace. 
Please make a backup of your a.lst file before running the script...



#!/usr/bin/perl

$file = '/root/testing/a.lst';
open(FILE, $file) or die "Can't open $file: $!\n";
@lines = <FILE>;
close FILE;

$new = 'b.lst';
open(NEW, ">$new") or die "Can't open $new for writing: $!\n";

foreach (@lines) {
  $_ =~ s/\s+$//g;
  print NEW "$_\n";
}

close NEW;




Chris Purcell, RHCE






More information about the redhat-list mailing list