Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl one-liner question: add file into text.

Reply
Thread Tools

perl one-liner question: add file into text.

 
 
ahq_2001
Guest
Posts: n/a
 
      05-13-2005
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.

AhQ

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      05-14-2005
ahq_2001 <> wrote in comp.lang.perl.misc:
> 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... )


So what did you try?

We're not in the business of translating scripts from whatever
language the poster happens to know. Take a look at s2p for sed.

Anno
 
Reply With Quote
 
 
 
 
Tsu Do Nimh
Guest
Posts: n/a
 
      05-17-2005
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|
|
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting a text file into an "insert into ..." file kublaikhan55@hotmail.com Ruby 5 07-23-2006 07:35 PM
Possibility to add a zip-file to a new zip-file with "add to zip" (right-click) ?? erikkie@casema.nl Computer Support 4 06-26-2006 12:18 AM
Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file. Tony Perl Misc 5 04-19-2004 03:28 PM
Perl command to copy one file into another file? Bill Perl Misc 8 09-30-2003 11:11 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57