Why not use awk?

cat your_text_file | awk -F= '{printf("%s %s\n",$1,$2)}' | xargs cp

That would DO the job... or

cat your_text_file | awk -F= '{printf("cp %s %s\n",$1,$2)}' > your_script

will produce a script just like what you would get from sed, and is easier
to read 8o

There are a couple hundred good ways to do this.... but it's like trolling
us script kiddies to come up with the tersest, or most elegant, or most
convoluted or.... 

Bill Ward

-----Original Message-----
From: Anthony E. Greene [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 13, 2000 1:31 PM
To: [EMAIL PROTECTED]
Subject: Re: shell script


Rodrigo Moya wrote:
> I've got a text file containing the following:
> 
> /dir/file1=/mnt/zip/dir/file1
> /dir/dir/file2=/mnt/zip/dir/dir/file1
> ...
> 
> and like this with hundreds of files. What I want is to read all the
> file and copy the files in the first position (to the left of '=') to
> the place specified by the string at the right of '='. But I don't know
> how to split the line from a shell script (as you guessed I'm quite bad
> at shell programming).

You could use sed to insert a "cp " at the beginning of each line then
replace the equals sign (=) with a space. The output would become a script
with all the desired copy commands, which can immediately be run by your
shell:

cat filelist.dat | sed -e "s/^/cp /" -e "s/=/ /" > ready2run.sh
bash ready2run.sh


Or you can use perl if you want to get fancy:

#!/usr/bin/perl
#
# Pipe the file lists into this script using something
# like this: this_script.pl < filelist.dat
#
while ($line = <STDIN>)
{
  @filenames = split('=',$line);
  $cmd = "cp $filenames[0] $filenames[1]";
  print "copying $filenames[0] to $filenames[1]\n";
  system($cmd);
}


Tony
-- 
 Anthony E. Greene <[EMAIL PROTECTED]>
 Homepage & PGP Key <http://www.pobox.com/~agreene/>
 If it's too good to be true, it's probably Linux.


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to