ahq_2001 wrote:
> Hi, Guys:
>
> I think perl should have the same ability to do this, but just not sure
> how. Any help is welcomed!!!
>
> Directory A (/home/dir_a) have these files:
> file_A, file_B, file_C.
>
> Directory B (/home/dir_b) have the corresponding notes:
> file_A_note, file_B_note, file_C_note.
>
>
> To append file_X_note into file_X at the end of the line
> "Put_Note_Here" in file_A:
> I know foreach + sed can do this with:
>
> In dir_A: use
>
> foreach f (*)
>> sed "/Put_Note_Here/ r ../dir_b/$f.note" $f >! tmp1 && mv tmp1 $f
>> end
>
> Can any one help to show how can I use perl one-liner ( and/or shell
> "foreach" ) to achieve the same function? (No offend to sed lover, but
> I just prefer using perl... )
>
> Many thanks.
>
> Ah
I know this one. Yay!
=8<======================
#! /usr/bin/perl -w
use strict;
use warnings;
my $destdir = shift or die "ugh: $!";
my $shcmd =<<NED;
for file in *
do
if [ -f \$file ]
then
cat \$file >> $destdir/\$file
fi
done
NED
print $shcmd;
exec $shcmd;
=8<======================
--
Tsu|
Do|
Nimh|

|