Hi,

perl -pi.bak -e 'tr/\xA0/ /' filenames*

# all files in a folder
find . | xargs perl -p -i.bak -e 's/oldstring/newstring/g'

perl  -e 's/string/stringier/gi'  -p  -i.bak  *.html

I'm accustomed to some of those.  But how do I or is it possible to file slurp 
on the command line, substituting \n+ with \n

IOW the next code does it.  But can I do this slurp/substitute directly on the 
commandline?  How?

#!/usr/bin/perl -w
use strict;

my $old = shift;
my $new = "$old.tmp";
open(OLD, "<", $old)  or die "cant open $old: $!";
my $text = do { local $/; <OLD> };
open(NEW, ">", $new)  or die "cant open $new: $!";
$text =~ s/\n+/\n/g;
print NEW <<HAL;
$text
HAL
close(OLD)  or die "cant close $old: $!";
close(NEW)  or die "cant close $new: $!";
rename($old, "$old.orig")  or die "cant rename $old to $old.orig: $!";
rename($new, "$old")  or die "cant rename $new to $old: $!";

-- 
Alan.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to