login
Header Space

 
 

Re: find -exec {} help

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <root@...>, David B. <incomex@...>, <misc@...>
Date: Monday, June 4, 2007 - 4:46 pm

On Mon, Jun 04, 2007 at 02:25:00PM +0200, Hannah Schroeter wrote:

newlines in file names are a pretty infrequent occurrence.

In case this could happen, I would do it in perl and get rid of the sed 
entirely.

#! /usr/bin/perl
use File::Find;

sub
transform
{
	my $filename = shift;
	open my $fh, '<', $filename or 
		die "Problem with $filename: $!\n";
	open my $fh2, '>', "$filename.new" or
		die "Problem with $filename.new: $!\n";
	while (<$fh>) {
		s/old/new/;
		print $fh2 $_
	}
}

find(sub {
	return unless -f $_;
	return unless m/\.htm$/;
	transform($_);
}, '.');

or something like this...
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
find -exec {} help, David B., (Mon Jun 4, 3:04 am)
Re: find -exec {} help, Stuart Henderson, (Mon Jun 4, 5:35 am)
Re: find -exec {} help, Almir Karic, (Mon Jun 4, 4:14 am)
Re: find -exec {} help, Bryan Irvine, (Mon Jun 4, 3:30 am)
Re: find -exec {} help, Marc Espie, (Mon Jun 4, 8:01 am)
Re: find -exec {} help, Martin Schröder, (Mon Jun 4, 9:26 am)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 11:28 am)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 8:25 am)
Re: find -exec {} help, Marc Espie, (Mon Jun 4, 4:46 pm)
Re: find -exec {} help, Tom Van Looy, (Mon Jun 4, 12:54 pm)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 4:30 pm)
Re: find -exec {} help, terry tyson, (Mon Jun 4, 5:37 pm)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 6:04 pm)
Re: find -exec {} help, Almir Karic, (Mon Jun 4, 12:27 pm)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 12:58 pm)
Re: find -exec {} help, Almir Karic, (Mon Jun 4, 1:49 pm)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 4:32 pm)
Re: find -exec {} help, Almir Karic, (Mon Jun 4, 5:45 pm)
Re: find -exec {} help, Hannah Schroeter, (Mon Jun 4, 6:21 pm)
Re: find -exec {} help, Marc Espie, (Mon Jun 4, 6:19 pm)
Re: find -exec {} help, Almir Karic, (Tue Jun 5, 2:20 am)
Re: find -exec {} help, Antti Harri, (Mon Jun 4, 3:24 am)
speck-geostationary