[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Perl/C programmers, help pls



On Mon, Apr 03, 2000 at 06:14:51PM +1000, Matthew Dalton wrote:
> 
> #!/usr/bin/perl
> 
> while (<STDIN>)
> {
>         s#http://209\.155\.163\.97/#http://www\.pexchange\.com/#g;
>         print;
> }
> 
> --
> 
> run it like:
> $ cat small_file | ./filter_above > new_small_file

mmmm... Perl... ;)

In this case, i'd probably just do something like this:

perl -i -pwe 's!http://209\.155\.163\.97!http://www\.pexchange\.com!g' filename

> To do all of the files in all of the subdirectories, you could probably
> write a shell script to do it. Two ways I can think of would be to use
> find to get a list of all of the files, and run them through this
> script...
> 
> #!/bin/sh
> 
> for file in `find .`; do
>     cat $file | ./filter > $file.new
>     rm -f $file
>     mv $file.new $file
> done

If you want to do something really ... interesting: (all one line)

find . \! -type d -exec perl -i -pwe 's!http://209\.155\.163\.97!http://www\.pexchange\.com!g' {} \;

> Warning!!! Please test this on non-important data before running it on
> your 30000 files. I'm claim no responsibility for what it does to your
> system.

I'll second that. i _think_ that my line above will work, but a backup
copy never hurt anyone.


-- 
  finger for GPG public key.

Attachment: pgpy5NcBsy8Ol.pgp
Description: PGP signature


Reply to: