Here a Perl solution:


I am not very good in Perl and your question was too vague to make a script adapted for your needs.

I made several files in a certain folder containing "this is file:" This script adds to this the file name: "this is file: filename".



#!/usr/bin/perl


use warnings;
use strict;
use File::Find;

my $start_dir = '/Users/path/to/start/folder';

find( \&wanted, $start_dir );

sub wanted {
    return unless /\.txt$/; # file extension you are searching for
    my $file_path = $File::Find::name;
    print "$file_path\n";
    $file_path =~ m~^.*?/([^/]+)$~;
    my $file_name = $1;
        open (IN, "+<", $file_path);
        my $out = "";
    while (<IN>) {
        # s/$file_name//; # this is the way back, removes the file_names
        s/this is file:\s*/$&$file_name/ig;
        $out .= $_;
    }
    seek(IN, 0, 0) or die "can't seek to start of $file_path: $!";
    print IN $out or die "can't print to $file_path: $!";
    truncate (IN, tell(IN)) or die "can't truncate $file_path: $!";
    close IN or die "can't close $file_path: $!";
}

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group.

Reply via email to