perl one-liner question: add file into text.

A

ahq_2001

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
 
A

Anno Siegel

ahq_2001 said:
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 (*)

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
 
T

Tsu Do Nimh

ahq_2001 said:
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 (*)

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<======================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top