[Linux-disciples] help me write a shell script

Stephen R Laniel steve at laniels.org
Thu Jul 17 11:28:07 EDT 2008


On Thu, Jul 17, 2008 at 11:23:58AM -0400, Jamie Forrest wrote:
> Is there any way here to modify this to work on stdin rather than a  
> file?

#!/usr/bin/perl
use strict;
use warnings;

my $file_contents = join( '', <> );
$file_contents =~ s#[^[:ascii:]]##gsmi;
print $file_contents;

So now you can do either

/path/to/myscript.pl filename

or

cat filename | /path/to/myscript.pl

or (it goes without saying)

cat filename | command1 | command2 | \
    command3 | ... | myscript.pl

-- 
Stephen R. Laniel
steve at laniels.org
Cell: +(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key


More information about the Linux-disciples mailing list